From 124133a4076c5963b8f564c75a1d5953c2008d5c Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sat, 28 Oct 2023 17:14:55 +0300 Subject: [PATCH] Refactor the simple substitute to use the decrypt-by-table function. --- .../ciphers/simple_substitution.clj | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cipher_analytical_machine/ciphers/simple_substitution.clj b/src/cipher_analytical_machine/ciphers/simple_substitution.clj index 95e1d6b..4514f0f 100644 --- a/src/cipher_analytical_machine/ciphers/simple_substitution.clj +++ b/src/cipher_analytical_machine/ciphers/simple_substitution.clj @@ -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?)