Skip to content

Commit 1e560a9

Browse files
committed
feat: morse支持自定义符号
1 parent 1ce2660 commit 1e560a9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

app/src/main/kotlin/me/leon/classical/Morse.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package me.leon.classical
33
import me.leon.ext.splitBySpace
44
import me.leon.ext.stripAllSpace
55

6+
// https://en.wikipedia.org/wiki/Morse_code
67
val DEFAULT_MORSE =
78
mapOf(
89
'A' to ".-",
@@ -42,15 +43,16 @@ val DEFAULT_MORSE =
4243
'9' to "----.",
4344
'0' to "-----",
4445
'.' to ".-.-.-",
45-
':' to "...---",
46+
':' to "---...",
4647
',' to "--..--",
4748
';' to "-.-.-.",
4849
'?' to "..--..",
4950
'=' to "-...-",
5051
'\'' to ".----.",
5152
'/' to "-..-.",
5253
'!' to "-.-.--",
53-
'-' to "-...-",
54+
'-' to "-....-",
55+
'+' to ".-.-.",
5456
'_' to "..--.-",
5557
'"' to ".-..-.",
5658
'(' to "-.--.",

app/src/main/kotlin/me/leon/ext/crypto/ClassicalCryptoType.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,17 @@ enum class ClassicalCryptoType(val type: String) : IClassical {
9696
},
9797
MORSE("morse") {
9898
override fun encrypt(raw: String, params: MutableMap<String, String>) = raw.morseEncrypt()
99+
.replace(".",params[P1].takeUnless { it.isNullOrEmpty() }?: ".")
100+
.replace("-",params[P2].takeUnless { it.isNullOrEmpty() }?: "-")
99101

100-
override fun decrypt(raw: String, params: MutableMap<String, String>) = raw.morseDecrypt()
102+
override fun decrypt(raw: String, params: MutableMap<String, String>) = raw
103+
.replace(params[P1].takeUnless { it.isNullOrEmpty() }?: ".",".")
104+
.replace(params[P2].takeUnless { it.isNullOrEmpty() }?: "-","-")
105+
.morseDecrypt()
106+
107+
override fun paramsCount() = 2
108+
109+
override fun paramsHints() = listOf("default .", "default -")
101110

102111
override fun isIgnoreSpace() = false
103112
},

0 commit comments

Comments
 (0)