This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
(ns cipher-analytical-machine.cli.actions.cryptography
|
(ns cipher-analytical-machine.cli.actions.cryptography
|
||||||
(:require
|
(: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))
|
(:gen-class))
|
||||||
|
|
||||||
(defn caesar-actions
|
(defn caesar-actions
|
||||||
@@ -15,10 +18,33 @@
|
|||||||
(= action-type :decrypt)
|
(= action-type :decrypt)
|
||||||
(caesar/decrypt-message message key symbols))))
|
(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
|
(defn cryptography-actions
|
||||||
[options arguments action-type]
|
[options arguments action-type]
|
||||||
(let [cipher (:cipher options)]
|
(let [cipher (:cipher options)]
|
||||||
(cond
|
(cond
|
||||||
(= cipher "Caesar")
|
(= 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))))
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
(option-values-as-list option values)))
|
(option-values-as-list option values)))
|
||||||
|
|
||||||
(def cipher-options
|
(def cipher-options
|
||||||
#{"Caesar"})
|
#{"Caesar" "Simple substitution and Caesar"})
|
||||||
|
|
||||||
(def default-cipher "Caesar")
|
(def default-cipher "Caesar")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user