Compare commits
3
Commits
e145382570
..
0.9.7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ddfd5c473d | ||
|
|
fcae272944 | ||
|
|
1e45771b3e |
@@ -9,7 +9,8 @@
|
|||||||
(let [analyzer (:analyzer options)
|
(let [analyzer (:analyzer options)
|
||||||
message (:message options)
|
message (:message options)
|
||||||
symbols (:symbols options)
|
symbols (:symbols options)
|
||||||
frequencies symbol-frequencies/english-letter-frequencies]
|
frequencies (-> (get options :language "en")
|
||||||
|
(symbol-frequencies/default-frequency-factory))]
|
||||||
(cond
|
(cond
|
||||||
(= analyzer "Chi^2")
|
(= analyzer "Chi^2")
|
||||||
(caesar-analyzers/get-plaintext message symbols frequencies)
|
(caesar-analyzers/get-plaintext message symbols frequencies)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
(ns cipher-analytical-machine.cli.cli
|
(ns cipher-analytical-machine.cli.cli
|
||||||
(:require
|
(:require
|
||||||
|
[cipher-analytical-machine.parsers.parsers :as ps]
|
||||||
|
[cipher-analytical-machine.parsers.gamma :as gamma-ps]
|
||||||
[cipher-analytical-machine.cli.file :as file]
|
[cipher-analytical-machine.cli.file :as file]
|
||||||
[cipher-analytical-machine.symbols.factories :as sf]
|
[cipher-analytical-machine.symbols.factories :as sf]
|
||||||
[cipher-analytical-machine.cli.options :as options]
|
[cipher-analytical-machine.cli.options :as options]
|
||||||
@@ -77,6 +79,15 @@
|
|||||||
(or (contains? options :encrypt)
|
(or (contains? options :encrypt)
|
||||||
(contains? options :decrypt)))
|
(contains? options :decrypt)))
|
||||||
(cond
|
(cond
|
||||||
|
(and (= (:cipher options) "Caesar")
|
||||||
|
(false? (ps/int-string? (:key options))))
|
||||||
|
{:exit-message (error-msg ["Please, use the key format: [+-](integer)!!! Example: 10, +9, -7."])}
|
||||||
|
|
||||||
|
(and (= (:cipher options) "Gamma")
|
||||||
|
(false? (gamma-ps/key? (:key options))))
|
||||||
|
{:exit-message (error-msg ["Please, use the key format: [+-](integer),[+-](integer),[+-](integer) !!! Example: 10,+9,-7."])}
|
||||||
|
|
||||||
|
|
||||||
(contains? options :encrypt)
|
(contains? options :encrypt)
|
||||||
{:options options :arguments arguments :action-type :encrypt}
|
{:options options :arguments arguments :action-type :encrypt}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
(ns cipher-analytical-machine.parsers.gamma
|
||||||
|
(:gen-class))
|
||||||
|
|
||||||
|
(defn key?
|
||||||
|
"Return true if the string is an key of three integers."
|
||||||
|
[str]
|
||||||
|
(if (re-matches #"[+-]?\b\d+\b,[+-]?\b\d+\b,[+-]?\b\d+\b" str)
|
||||||
|
true false))
|
||||||
|
|
||||||
@@ -77,3 +77,16 @@
|
|||||||
\ 0.138
|
\ 0.138
|
||||||
})
|
})
|
||||||
|
|
||||||
|
(defn default-frequency-factory
|
||||||
|
"Returns a default map of letter frequencies for a language"
|
||||||
|
[language-code]
|
||||||
|
(cond
|
||||||
|
(= language-code "en")
|
||||||
|
english-letter-frequencies
|
||||||
|
|
||||||
|
(= language-code "uk")
|
||||||
|
ukrainian-letter-frequencies
|
||||||
|
|
||||||
|
:else
|
||||||
|
english-letter-frequencies))
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
(ns cipher-analytical-machine.parsers.gamma-test
|
||||||
|
(:require
|
||||||
|
[clojure.test :refer :all]
|
||||||
|
[cipher-analytical-machine.parsers.gamma :refer :all]))
|
||||||
|
|
||||||
|
(deftest key?-test
|
||||||
|
(testing "The function return true only if the key in the format '%d,%d,%d'."
|
||||||
|
(are [str expected]
|
||||||
|
(= expected
|
||||||
|
(key? str))
|
||||||
|
"9" false
|
||||||
|
"9,10" false
|
||||||
|
"10,9,8" true
|
||||||
|
"-10,9,-8" true
|
||||||
|
"-10,-9,-8" true
|
||||||
|
"asd 10 " false
|
||||||
|
" 10 " false
|
||||||
|
"-10" false
|
||||||
|
"abc" false)))
|
||||||
|
|
||||||
@@ -9,3 +9,13 @@
|
|||||||
(is (= "etaoinsrhldcumfpgwybvkxjqz"
|
(is (= "etaoinsrhldcumfpgwybvkxjqz"
|
||||||
(map-to-string symbol-map))))))
|
(map-to-string symbol-map))))))
|
||||||
|
|
||||||
|
(deftest default-frequency-factory-test
|
||||||
|
(testing "Factory supports languages: English (en), Ukrainian (uk). If language code is unidentified, then it must have the 'en'."
|
||||||
|
(are [language-code expected-map-size]
|
||||||
|
(->> (default-frequency-factory language-code)
|
||||||
|
count
|
||||||
|
(= expected-map-size))
|
||||||
|
"en" 26
|
||||||
|
"uk" 34
|
||||||
|
"Maybe a code" 26)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user