|
|
@ -88,29 +88,65 @@
|
|
|
|
(println exit-message)
|
|
|
|
(println exit-message)
|
|
|
|
(System/exit (if status 0 1)))
|
|
|
|
(System/exit (if status 0 1)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn get-message
|
|
|
|
(defn get-or-load-option
|
|
|
|
"Return the message"
|
|
|
|
"Return the option value or load the value from a file."
|
|
|
|
[options arguments]
|
|
|
|
[options arguments option]
|
|
|
|
|
|
|
|
(let [file-option (keyword (str (name option) "-file"))]
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
(contains? options :message)
|
|
|
|
(contains? options option)
|
|
|
|
(:message options)
|
|
|
|
(option options)
|
|
|
|
|
|
|
|
|
|
|
|
(contains? options :message-file)
|
|
|
|
(contains? options file-option)
|
|
|
|
(file/read-file (:message-file options))))
|
|
|
|
(file/read-file (file-option options)))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn set-option
|
|
|
|
|
|
|
|
"Set a option in the option map."
|
|
|
|
|
|
|
|
[options option value]
|
|
|
|
|
|
|
|
(-> options
|
|
|
|
|
|
|
|
(assoc option value)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn load-and-set-option
|
|
|
|
|
|
|
|
"Load the option and set it."
|
|
|
|
|
|
|
|
[options option]
|
|
|
|
|
|
|
|
(->> (get-or-load-option options nil option)
|
|
|
|
|
|
|
|
(set-option options option)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn load-all-options
|
|
|
|
|
|
|
|
"Load all options."
|
|
|
|
|
|
|
|
[options]
|
|
|
|
|
|
|
|
(-> options
|
|
|
|
|
|
|
|
(load-and-set-option :message)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn cracking-actions
|
|
|
|
|
|
|
|
[options arguments action-type]
|
|
|
|
|
|
|
|
(let [message (:message options)
|
|
|
|
|
|
|
|
symbols (:symbols options)
|
|
|
|
|
|
|
|
frequencies symbol-frequences/english-letter-frequences]
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
(= action-type :cracking)
|
|
|
|
|
|
|
|
(caesar-analyzers/get-plaintext message symbols frequencies)
|
|
|
|
|
|
|
|
)))
|
|
|
|
|
|
|
|
|
|
|
|
(defn actions
|
|
|
|
(defn crypt-actions
|
|
|
|
[options arguments action-type]
|
|
|
|
[options arguments action-type]
|
|
|
|
(let [message (get-message options arguments)
|
|
|
|
(let [message (:message options)
|
|
|
|
key (Integer/parseInt (:key options))
|
|
|
|
key (Integer/parseInt (:key options))
|
|
|
|
symbols (:symbols options)]
|
|
|
|
symbols (:symbols options)]
|
|
|
|
(println
|
|
|
|
|
|
|
|
(cond
|
|
|
|
(cond
|
|
|
|
(= action-type :cracking)
|
|
|
|
|
|
|
|
(caesar-analyzers/get-plaintext message symbols symbol-frequences/english-letter-frequences)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(= action-type :encrypt)
|
|
|
|
(= action-type :encrypt)
|
|
|
|
(caesar/encrypt-message message key symbols)
|
|
|
|
(caesar/encrypt-message message key symbols)
|
|
|
|
|
|
|
|
|
|
|
|
(= action-type :decrypt)
|
|
|
|
(= action-type :decrypt)
|
|
|
|
(caesar/decrypt-message message key symbols)))))
|
|
|
|
(caesar/decrypt-message message key symbols))))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defn actions
|
|
|
|
|
|
|
|
[options arguments action-type]
|
|
|
|
|
|
|
|
(let [options (load-all-options options)]
|
|
|
|
|
|
|
|
(println
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
|
|
|
(contains? #{:encrypt :decrypt} action-type)
|
|
|
|
|
|
|
|
(crypt-actions options arguments action-type)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(= action-type :cracking)
|
|
|
|
|
|
|
|
(cracking-actions options arguments action-type)))))
|
|
|
|
|
|
|
|
|
|
|
|