diff --git a/src/cipher_analytical_machine/cli/actions/cryptography.clj b/src/cipher_analytical_machine/cli/actions/cryptography.clj index cdddd12..8a34e6d 100644 --- a/src/cipher_analytical_machine/cli/actions/cryptography.clj +++ b/src/cipher_analytical_machine/cli/actions/cryptography.clj @@ -1,6 +1,9 @@ (ns cipher-analytical-machine.cli.actions.cryptography (:require - [cipher-analytical-machine.ciphers.caesar :as caesar]) + [cipher-analytical-machine.ciphers.caesar :as caesar] + [cipher-analytical-machine.ciphers.simple-substitution :as ss] + [cipher-analytical-machine.parsers.parsers :as ps] + [cipher-analytical-machine.parsers.simple-substitution :as pss]) (:gen-class)) (defn caesar-actions @@ -15,10 +18,33 @@ (= action-type :decrypt) (caesar/decrypt-message message key symbols)))) +(defn simple-substitution-with-caesar-actions + [options arguments action-type] + (let [message (:message options) + key (:key options) + symbols (:symbols options)] + (cond + (= action-type :encrypt) + (let [data (pss/generate-table-or-decode-json key symbols) + key (ps/parse-unsigned-int (get data "key")) + substitution-table (get data "table")] + (println (pss/encode-key-and-substitution-table-to-json key substitution-table)) + (ss/encrypt-message-with-caesar message key substitution-table symbols)) + + (= action-type :decrypt) + (let [data (-> (pss/decode-key-and-substitution-table-from-json key) + (pss/invert-table-in-map)) + key (get data "key") + substitution-table (get data "table")] + (ss/decrypt-message-with-caesar message key substitution-table symbols))))) + (defn cryptography-actions [options arguments action-type] (let [cipher (:cipher options)] (cond (= cipher "Caesar") - (caesar-actions options arguments action-type)))) + (caesar-actions options arguments action-type) + + (= cipher "Simple substitution and Caesar") + (simple-substitution-with-caesar-actions options arguments action-type)))) diff --git a/src/cipher_analytical_machine/cli/options.clj b/src/cipher_analytical_machine/cli/options.clj index 0c9d968..fc9394e 100644 --- a/src/cipher_analytical_machine/cli/options.clj +++ b/src/cipher_analytical_machine/cli/options.clj @@ -22,7 +22,7 @@ (option-values-as-list option values))) (def cipher-options - #{"Caesar"}) + #{"Caesar" "Simple substitution and Caesar"}) (def default-cipher "Caesar")