Add the clojure wrapper for the frequency analizer and its test.
continuous-integration/drone/push Build is passing Details

dev 0.5.4
KKlochko 2 years ago
parent 40af8401b2
commit 51609b1d27

@ -2,6 +2,8 @@
(:require [cipher-analytical-machine.caesar :as caesar] (:require [cipher-analytical-machine.caesar :as caesar]
[clojure.string :as cs] [clojure.string :as cs]
[cipher-analytical-machine.cipher-analyzers :as ca]) [cipher-analytical-machine.cipher-analyzers :as ca])
(:import [cipher_analytical_machine.ciphers.caesar Decrypted]
[cipher_analytical_machine.analizers.caesar FrequencyAnalyzer])
(:gen-class)) (:gen-class))
(defn get-all-texts (defn get-all-texts
@ -46,3 +48,12 @@
(get-key ciphertext symbols letter-frequences) (get-key ciphertext symbols letter-frequences)
symbols))) symbols)))
(defn frequency-analizer-get-plaintext
"Return the plaintext from a ciphertext using simple analizer. The function is case-insensitive."
[ciphertext symbols letter-frequences]
(let [decrypt (reify Decrypted
(decrypt [this message key symbols]
(caesar/decrypt-message message key symbols)))]
(-> (new FrequencyAnalyzer ciphertext symbols letter-frequences decrypt)
.crack)))

@ -74,3 +74,13 @@
(is (= (cs/lower-case plaintext) (is (= (cs/lower-case plaintext)
(get-plaintext ciphertext symbols frequences)))))) (get-plaintext ciphertext symbols frequences))))))
(deftest frequency-analizer-get-plaintext-test
(let [plaintext "abc"
ciphertext "bca"
key 1
symbols "abc"
frequences sf/english-letter-frequences]
(testing "The ciphertext is 'bca' and key is 1."
(is (= plaintext
(frequency-analizer-get-plaintext ciphertext symbols frequences))))))

Loading…
Cancel
Save