From 6339774bd13238fa0113b3aa995f49c952f456ab Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sat, 14 Oct 2023 17:22:03 +0300 Subject: [PATCH] Add the analyzer options and their actions. --- src/cipher_analytical_machine/cli/cli.clj | 20 +++++++++++++++---- src/cipher_analytical_machine/cli/options.clj | 4 ++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/cipher_analytical_machine/cli/cli.clj b/src/cipher_analytical_machine/cli/cli.clj index 689fed4..73f349f 100644 --- a/src/cipher_analytical_machine/cli/cli.clj +++ b/src/cipher_analytical_machine/cli/cli.clj @@ -132,14 +132,26 @@ (save-output output options)) (println output)) -(defn cracking-actions - [options arguments action-type] - (let [message (:message options) +(defn cracking-caesar + [options arguments] + (let [analyzer (:analyzer options) + message (:message options) symbols (:symbols options) frequencies symbol-frequencies/english-letter-frequencies] (cond - (= action-type :cracking) + (= analyzer "Chi^2") (caesar-analyzers/get-plaintext message symbols frequencies) + + (= analyzer "Frequency") + (caesar-analyzers/frequency-analizer-get-plaintext message symbols + (symbol-frequencies/map-to-string frequencies))))) + +(defn cracking-actions + [options arguments action-type] + (let [cipher (:cipher options)] + (cond + (= cipher "Caesar") + (cracking-caesar options arguments) ))) (defn crypt-actions diff --git a/src/cipher_analytical_machine/cli/options.clj b/src/cipher_analytical_machine/cli/options.clj index fcf1023..a1c1434 100644 --- a/src/cipher_analytical_machine/cli/options.clj +++ b/src/cipher_analytical_machine/cli/options.clj @@ -9,6 +9,9 @@ (def default-cipher "Caesar") +(def analyzers-options + {"Caesar" #{"Chi^2" "Frequency"}}) + (def language-options #{"en", "uk"}) @@ -28,6 +31,7 @@ ["-l" "--language CODE" "The string will be used to set a default symbols for a cipher." :validate [#(contains? language-options %) "Must be a code from the list: en, uk!!!"]] ["-C" "--cracking" "Cracking the encrypted message."] + ["-a" "--analyzer ANALYZER" "The way of cracking."] ["-O" "--output-file OUTPUT-FILE" "Save the program output to a file."] ["-h" "--help"]])