From e3954804c840c5de281e9ed1d1d6d9cf06156ad7 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 17 Sep 2023 21:45:09 +0300 Subject: [PATCH] Add the cracking option. --- src/cipher_analytical_machine/cli.clj | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cipher_analytical_machine/cli.clj b/src/cipher_analytical_machine/cli.clj index 74e8555..8b51deb 100644 --- a/src/cipher_analytical_machine/cli.clj +++ b/src/cipher_analytical_machine/cli.clj @@ -2,7 +2,9 @@ (:require [cipher-analytical-machine.file :as file] [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-frequences :as symbol-frequences] [clojure.string :as cs] [clojure.tools.cli :refer [parse-opts]]) (:gen-class)) @@ -20,6 +22,7 @@ ["-d" "--decrypt" "Decrypt the message."] ["-s" "--symbols" "The string will be used as a set of symbols for a cipher." :default (sf/default-symbol-factory "en")] + ["-C" "--cracking" "Cracking the encrypted message."] ["-h" "--help"]]) (defn usage [options-summary] @@ -72,6 +75,11 @@ (contains? options :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 {:exit-message (usage summary)}))) @@ -97,6 +105,9 @@ symbols (:symbols options)] (println (cond + (= action-type :cracking) + (caesar-analyzers/get-plaintext message symbols symbol-frequences/english-letter-frequences) + (= action-type :encrypt) (caesar/encrypt-message message key symbols)