Add the cracking option.
continuous-integration/drone/push Build is passing Details

main 0.4.1
KKlochko 2 years ago
parent b1f3bb8585
commit e3954804c8

@ -2,7 +2,9 @@
(:require (:require
[cipher-analytical-machine.file :as file] [cipher-analytical-machine.file :as file]
[cipher-analytical-machine.caesar :as caesar] [cipher-analytical-machine.caesar :as caesar]
[cipher-analytical-machine.caesar-analyzers :as caesar-analyzers]
[cipher-analytical-machine.symbol-factories :as sf] [cipher-analytical-machine.symbol-factories :as sf]
[cipher-analytical-machine.symbol-frequences :as symbol-frequences]
[clojure.string :as cs] [clojure.string :as cs]
[clojure.tools.cli :refer [parse-opts]]) [clojure.tools.cli :refer [parse-opts]])
(:gen-class)) (:gen-class))
@ -20,6 +22,7 @@
["-d" "--decrypt" "Decrypt the message."] ["-d" "--decrypt" "Decrypt the message."]
["-s" "--symbols" "The string will be used as a set of symbols for a cipher." ["-s" "--symbols" "The string will be used as a set of symbols for a cipher."
:default (sf/default-symbol-factory "en")] :default (sf/default-symbol-factory "en")]
["-C" "--cracking" "Cracking the encrypted message."]
["-h" "--help"]]) ["-h" "--help"]])
(defn usage [options-summary] (defn usage [options-summary]
@ -72,6 +75,11 @@
(contains? options :decrypt) (contains? options :decrypt)
{:options options :arguments arguments :action-type :decrypt}) {:options options :arguments arguments :action-type :decrypt})
(and (map-has-keys? options [:cipher, :cracking])
(or (contains? options :message)
(contains? options :message-file)))
{:options options :arguments arguments :action-type :cracking}
:else :else
{:exit-message (usage summary)}))) {:exit-message (usage summary)})))
@ -97,6 +105,9 @@
symbols (:symbols options)] symbols (:symbols options)]
(println (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)

Loading…
Cancel
Save