Refactor the simple substitute to use the decrypt-by-table function.

dev 0.9.1
KKlochko 2 years ago
parent e80e3a6cf0
commit 124133a407

@ -29,11 +29,16 @@
[char substitution-table]
(get substitution-table char))
(defn decrypt-by-table
"Decrypt a message by the substitution-table"
[substitution-table message]
(map (fn [char] (find-value-in-table char substitution-table)) message))
(defn encrypt-message
"Encrypt a message using the simple substitution cipher. The function is case-insensitive. If a symbol isn't in the symbols list, then it will be removed."
[message substitution-table]
(->> message
(map (fn [char] (find-value-in-table char substitution-table)))
(decrypt-by-table substitution-table)
(remove nil?)
(cs/join \,)))
@ -44,11 +49,6 @@
(caesar/encrypt-message key symbols)
(encrypt-message substitution-table)))
(defn decrypt-by-table
"Decrypt a message by the substitution-table"
[substitution-table message]
(map (fn [char] (find-value-in-table char substitution-table)) message))
(defn decrypt-message-by-symbol-table
"Decrypt a message using the simple substitution cipher. The function is case-insensitive. The substitution-table must be (symbols, symbols)."
[substitution-table message]

Loading…
Cancel
Save