Update the simple substitution cipher to split the decrypt-message.
continuous-integration/drone/push Build is passing Details

dev 0.8.4
KKlochko 2 years ago
parent 172f85ea6f
commit e70b72f0ec

@ -44,15 +44,26 @@
(caesar/encrypt-message key symbols) (caesar/encrypt-message key symbols)
(encrypt-message substitution-table))) (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 ]
(->> message
(decrypt-by-table substitution-table)
(remove nil?)
(cs/join)))
(defn decrypt-message (defn decrypt-message
"Decrypt a message using the simple substitution cipher. The function is case-insensitive. The substitution-table must be " "Decrypt a message using the simple substitution cipher. The function is case-insensitive. The substitution-table must be (int, symbols)."
[message substitution-table] [message substitution-table]
(let [message (cs/split message #",")] (let [message (cs/split message #",")]
(->> message (->> message
(map #(Integer/parseInt %)) (map #(Integer/parseInt %))
(map (fn [char] (find-value-in-table char substitution-table))) (decrypt-message-by-symbol-table substitution-table))))
(remove nil?)
(cs/join))))
(defn decrypt-message-with-caesar (defn decrypt-message-with-caesar
"Decrypt a message using the simple substitution cipher and the Caesar cipher. The function is case-insensitive." "Decrypt a message using the simple substitution cipher and the Caesar cipher. The function is case-insensitive."

@ -48,6 +48,23 @@
"abc" 1 "2,3,1" "abc" 1 "2,3,1"
"aDbdc" 0 "1,2,3")))) "aDbdc" 0 "1,2,3"))))
(deftest decrypt-by-table-test
(let [table {\d \a \e \b \f \c}]
(testing "The function must decrypt the message by the table."
(are [message expected]
(= expected (decrypt-by-table table message))
"def" '(\a \b \c)
"abf" '(nil nil \c)
"fed" '(\c \b \a)))))
(deftest decrypt-message-by-symbol-table-test
(let [table {\d \a \e \b \f \c}]
(testing "The function must decrypt the message and remove unknown numbers."
(are [message expected]
(= expected (decrypt-message-by-symbol-table table message))
"def" "abc"
"daef" "abc"))))
(deftest decrypt-message-test (deftest decrypt-message-test
(let [table {1 \a 2 \b 3 \c}] (let [table {1 \a 2 \b 3 \c}]
(testing "The function must decrypt the message and remove unknown numbers." (testing "The function must decrypt the message and remove unknown numbers."

Loading…
Cancel
Save