Refactor the simple substitute to use the decrypt-by-table function.
This commit is contained in:
@@ -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,14 +49,9 @@
|
||||
(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 ]
|
||||
[substitution-table message]
|
||||
(->> message
|
||||
(decrypt-by-table substitution-table)
|
||||
(remove nil?)
|
||||
|
||||
Reference in New Issue
Block a user