Skip to content

Commit

Permalink
style: format
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon406 committed Nov 27, 2024
1 parent 6358bfe commit ecc10ee
Show file tree
Hide file tree
Showing 180 changed files with 533 additions and 720 deletions.
2 changes: 1 addition & 1 deletion app/src/main/kotlin/me/leon/Digests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ val ALGOS_HASH =
"512-512",
"1024-384",
"1024-512",
"1024-1024"
"1024-1024",
),
"GOST3411" to listOf("256"),
"GOST3411-2012" to listOf("256", "512"),
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/me/leon/classical/ADFGX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fun String.adfgx(
table: String,
keyword: String,
encodeMap: String = ADFGX_ENCODE_MAP,
replacePair: Pair<String, String> = "J" to "I"
replacePair: Pair<String, String> = "J" to "I",
): String {
val key = keyword.distinct()
val polybius = polybius(table, encodeMap, replacePair)
Expand All @@ -29,7 +29,7 @@ fun String.adfgx(
fun String.adfgxDecrypt(
table: String,
keyword: String,
encodeMap: String = ADFGX_ENCODE_MAP
encodeMap: String = ADFGX_ENCODE_MAP,
): String {
val key = keyword.distinct()
val sortedKey = key.sorted()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/me/leon/classical/AlphabetaIndex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import me.leon.ext.crypto.TABLE_A_Z
fun String.alphabetIndex(
table: String = TABLE_A_Z,
delimiter: String = " ",
fromZero: Boolean = false
fromZero: Boolean = false,
) =
uppercase()
.asIterable()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/me/leon/classical/AutoKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fun String.autoKeyDecrypt(keyword: String): String {
.virgeneneDecode(keyBuilder.toString(), keyBuilder.length)
.substring(
keyBuilder.length - key.length,
keyBuilder.length.takeIf { it < stripText.length } ?: stripText.length
keyBuilder.length.takeIf { it < stripText.length } ?: stripText.length,
)
keyBuilder.append(substring)
}
Expand Down
9 changes: 1 addition & 8 deletions app/src/main/kotlin/me/leon/classical/HackWord.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ package me.leon.classical
* @email deadogone@gmail.com
*/
private val HACKER_DICT =
mapOf(
"A" to "4",
"E" to "3",
"I" to "1",
"O" to "0",
"S" to "5",
"T" to "7",
)
mapOf("A" to "4", "E" to "3", "I" to "1", "O" to "0", "S" to "5", "T" to "7")

private val HACKER_DICT_REVERSE = HACKER_DICT.values.zip(HACKER_DICT.keys).toMap()

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/me/leon/classical/NihilistCipher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import me.leon.ext.stripAllSpace
fun String.nihilist(
keyword: String,
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP,
replacePair: Pair<String, String> = "J" to "I"
replacePair: Pair<String, String> = "J" to "I",
): String {
val maps = TABLE_A_Z_WO_J.toMutableList()
keyword.stripAllSpace().uppercase().asIterable().distinct().also {
Expand All @@ -19,7 +19,7 @@ fun String.nihilist(

fun String.nihilistDecrypt(
keyword: String,
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP,
): String {
val maps = TABLE_A_Z_WO_J.toMutableList()
keyword.stripAllSpace().uppercase().asIterable().distinct().also {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/me/leon/classical/PolybiusSquareCipher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const val DEFAULT_POLYBIUS_ENCODE_MAP = "12345"
fun String.polybius(
table: String = TABLE_A_Z_WO_J,
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP,
replacePair: Pair<String, String> = "J" to "I"
replacePair: Pair<String, String> = "J" to "I",
): String {
val properTable = table.stripAllSpace().uppercase()
val map =
Expand All @@ -25,7 +25,7 @@ fun String.polybius(

fun String.polybiusDecrypt(
table: String = TABLE_A_Z_WO_J,
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP,
): String {
val properTable = table.stripAllSpace().uppercase()
val map =
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/me/leon/classical/TapCodeCipher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import me.leon.ext.crypto.TABLE_A_Z_WO_K
/** @link http://www.hiencode.com/tapcode.html */
fun String.tapCode(
table: String = TABLE_A_Z_WO_K,
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP,
) = polybius(table, encodeMap, "K" to "C")

fun String.tapCodeDecrypt(
table: String = TABLE_A_Z_WO_K,
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP
encodeMap: String = DEFAULT_POLYBIUS_ENCODE_MAP,
) = propTapCode().polybiusDecrypt(table, encodeMap)

private fun String.propTapCode() =
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/me/leon/component/AbsToggleView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import tornadofx.visibleWhen
abstract class AbsToggleView(
val data: List<String> = listOf("raw", "hex", "base64"),
var selectedIndex: Int = 0,
private val visible: BooleanProperty = SimpleBooleanProperty(true)
private val visible: BooleanProperty = SimpleBooleanProperty(true),
) : View() {

val tg: ToggleGroup = ToggleGroup()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/me/leon/component/KeyIvInputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import tornadofx.*
class KeyIvInputView(
private val enableIv: SimpleBooleanProperty = SimpleBooleanProperty(true),
private val enableAssociatedData: SimpleBooleanProperty = SimpleBooleanProperty(false),
private val autoConvert: SimpleBooleanProperty = SimpleBooleanProperty(false)
private val autoConvert: SimpleBooleanProperty = SimpleBooleanProperty(false),
) : View() {
private val toggleKey = ToggleVerticalView()
private val toggleIv = ToggleVerticalView(show = enableIv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tornadofx.*
class ToggleHorizontalView(
val list: List<String> = listOf("raw", "hex", "base64"),
var index: Int = 0,
show: SimpleBooleanProperty = SimpleBooleanProperty(true)
show: SimpleBooleanProperty = SimpleBooleanProperty(true),
) : AbsToggleView(list, index, show) {

override val root = hbox { populate() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import tornadofx.*
class ToggleVerticalView(
val list: List<String> = listOf("raw", "hex", "base64"),
var index: Int = 0,
show: SimpleBooleanProperty = SimpleBooleanProperty(true)
show: SimpleBooleanProperty = SimpleBooleanProperty(true),
) : AbsToggleView(list, index, show) {

override val root = vbox { populate() }
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/me/leon/component/Tray.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object Tray {
TrayIcon(
Toolkit.getDefaultToolkit()
.getImage(Tray.javaClass.getResource(IMG_ICON)),
"ToolsFx"
"ToolsFx",
)
.apply {
isImageAutoSize = true
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/me/leon/config/DictionaryConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data class DictionaryConfig(
val active: Int,
val dictFileName: String? = null,
val autoPronounce: Boolean = true,
val dicts: List<Dict>
val dicts: List<Dict>,
) {

val dictFile
Expand All @@ -19,7 +19,7 @@ data class DictionaryConfig(
val name: String,
val url: String,
val hideCssElement: String,
val js: String?
val js: String?,
) {
var autoPronounce: Boolean = true
}
Expand Down
7 changes: 1 addition & 6 deletions app/src/main/kotlin/me/leon/config/EncodeConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import me.leon.ext.crypto.EncodeType
* @email deadogone@gmail.com
*/
val BASE_ENCODE_EXCLUDED_DICT_LIST =
arrayOf(
EncodeType.BASE100,
EncodeType.BASE2048,
EncodeType.BASE32768,
EncodeType.BASE65536,
)
arrayOf(EncodeType.BASE100, EncodeType.BASE2048, EncodeType.BASE32768, EncodeType.BASE65536)

val SHOW_DICT_LIST = arrayOf(EncodeType.RADIX_N, EncodeType.DECIMAL_RADIX_N)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AsymmetricCryptoController : Controller() {
singleLine: Boolean = false,
reserved: Int = 11,
inputEncode: String = "raw",
outputEncode: String = "base64"
outputEncode: String = "base64",
): String =
catch({ "encrypt error: $it}" }) {
if (DEBUG) println("encrypt $key $alg $data")
Expand Down Expand Up @@ -48,7 +48,7 @@ class AsymmetricCryptoController : Controller() {
data: String,
singleLine: Boolean = false,
inputEncode: String = "base64",
outputEncode: String = "raw"
outputEncode: String = "raw",
): String =
catch({ "decrypt error: $it" }) {
if (DEBUG) println("decrypt $key $alg $data")
Expand All @@ -70,7 +70,7 @@ class AsymmetricCryptoController : Controller() {
singleLine: Boolean = false,
reserved: Int = 11,
inputEncode: String = "raw",
outputEncode: String = "base64"
outputEncode: String = "base64",
): String =
catch({ "encrypt error: $it" }) {
if (singleLine) {
Expand All @@ -93,7 +93,7 @@ class AsymmetricCryptoController : Controller() {
data: String,
singleLine: Boolean = false,
inputEncode: String = "base64",
outputEncode: String = "raw"
outputEncode: String = "raw",
) =
catch({ "decrypt error: $it" }) {
if (DEBUG) println("decrypt $key $alg $data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import me.leon.ext.crypto.calculatorType
import tornadofx.*

class CalculatorController : Controller() {
fun calculate(
algo: String,
radix: Int,
params: List<String>,
): String =
fun calculate(algo: String, radix: Int, params: List<String>): String =
catch({ "error $it" }) {
if (DEBUG) println("alg $algo radix $radix")
algo
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/kotlin/me/leon/controller/ClassicalController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ClassicalController : Controller() {
raw: String,
type: ClassicalCryptoType = ClassicalCryptoType.CAESAR,
params: Map<String, String>,
singleLine: Boolean = false
singleLine: Boolean = false,
) =
catch({ "编码错误: $it" }) {
if (singleLine) {
Expand All @@ -24,7 +24,7 @@ class ClassicalController : Controller() {
private fun encrypt(
raw: String,
type: ClassicalCryptoType = ClassicalCryptoType.CAESAR,
params: Map<String, String>
params: Map<String, String>,
): String =
if (raw.isEmpty()) {
""
Expand All @@ -36,7 +36,7 @@ class ClassicalController : Controller() {
encoded: String,
type: ClassicalCryptoType = ClassicalCryptoType.CAESAR,
params: Map<String, String>,
singleLine: Boolean = false
singleLine: Boolean = false,
) =
catch({ "解密错误: $it" }) {
if (singleLine) {
Expand All @@ -51,7 +51,7 @@ class ClassicalController : Controller() {
type: ClassicalCryptoType = ClassicalCryptoType.CAESAR,
keyword: String,
singleLine: Boolean = false,
params: Map<String, String>
params: Map<String, String>,
) =
catch({ "解密错误: $it" }) {
if (singleLine) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/me/leon/controller/DigestController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DigestController : Controller() {
method: String,
data: String,
inputEncode: String = "raw",
singleLine: Boolean = false
singleLine: Boolean = false,
) =
catch({ "digest error: $it" }) {
if (singleLine) {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/kotlin/me/leon/controller/EncodeController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class EncodeController : Controller() {
type: EncodeType = EncodeType.BASE64,
dic: String = "",
charset: String = UTF8,
singleLine: Boolean = false
singleLine: Boolean = false,
): String =
if (singleLine) {
raw.lineAction2String {
Expand All @@ -54,7 +54,7 @@ class EncodeController : Controller() {
raw: ByteArray,
type: EncodeType = EncodeType.BASE64,
dic: String = "",
charset: String = UTF8
charset: String = UTF8,
): String =
catch({ "编码错误: $it" }) {
if (DEBUG) {
Expand All @@ -72,7 +72,7 @@ class EncodeController : Controller() {
type: EncodeType = EncodeType.BASE64,
dic: String = "",
charset: String = UTF8,
singleLine: Boolean = false
singleLine: Boolean = false,
): String =
if (singleLine) {
encoded.lineAction2String {
Expand All @@ -88,15 +88,15 @@ class EncodeController : Controller() {
dic: String = "",
charset: String = UTF8,
singleLine: Boolean = false,
isFile: Boolean = false
isFile: Boolean = false,
): String =
if (isFile && encoded.length < 1024) {
val file = encoded.toFile()
val name = file.name.replace(".enc", "")
val out =
File(
file.parentFile,
name.takeIf { file.extension.isNotEmpty() && file.name != name } ?: "$name.dec"
name.takeIf { file.extension.isNotEmpty() && file.name != name } ?: "$name.dec",
)
out.outputStream().use {
it.write(decode(encoded.toFile().readText(), type, dic, charset))
Expand All @@ -110,7 +110,7 @@ class EncodeController : Controller() {
encoded: String,
type: EncodeType = EncodeType.BASE64,
dic: String = "",
charset: String = UTF8
charset: String = UTF8,
): ByteArray =
catch({ "解码错误: ${it.lines().first()}".toByteArray() }) {
if (DEBUG) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/me/leon/controller/MacController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MacController : Controller() {
alg: String,
inputEncode: String,
outputEncode: String,
singleLine: Boolean = false
singleLine: Boolean = false,
) =
catch({ "mac error: $it" }) {
if (DEBUG) println("mac $msg $alg ")
Expand All @@ -34,7 +34,7 @@ class MacController : Controller() {
alg: String,
inputEncode: String,
outputEncode: String,
singleLine: Boolean = false
singleLine: Boolean = false,
) =
catch({ "mac error: $it" }) {
if (singleLine) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/me/leon/controller/MiscController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MiscController : Controller() {
fun process(
type: MiscServiceType,
input: String,
params: Map<String, String> = emptyMap()
params: Map<String, String> = emptyMap(),
): String {
return runCatching { type.process(input, params) }.getOrElse { it.stacktrace() }
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/kotlin/me/leon/controller/PBEController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PBEController : Controller() {
alg: String,
iteration: Int,
keyLength: Int,
singleLine: Boolean
singleLine: Boolean,
) =
catch({ "encrypt error: $it" }) {
if (DEBUG) println("encrypt $alg $data")
Expand All @@ -34,7 +34,7 @@ class PBEController : Controller() {
alg: String,
iteration: Int,
keyLength: Int,
singleLine: Boolean
singleLine: Boolean,
) =
catch({ "decrypt error: $it" }) {
if (DEBUG) println("decrypt $alg $data")
Expand Down
Loading

0 comments on commit ecc10ee

Please sign in to comment.