Compare commits
2
Commits
0.6.0
...
becb168e0c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
becb168e0c | ||
|
|
de35d4e2d3 |
@@ -50,10 +50,10 @@
|
|||||||
|
|
||||||
(defn frequency-analizer-get-plaintext
|
(defn frequency-analizer-get-plaintext
|
||||||
"Return the plaintext from a ciphertext using simple analizer. The function is case-insensitive."
|
"Return the plaintext from a ciphertext using simple analizer. The function is case-insensitive."
|
||||||
[ciphertext symbols letter-frequences]
|
[ciphertext symbols letter-frequencies-string]
|
||||||
(let [decrypt (reify Decrypted
|
(let [decrypt (reify Decrypted
|
||||||
(decrypt [this message key symbols]
|
(decrypt [this message key symbols]
|
||||||
(caesar/decrypt-message message key symbols)))]
|
(caesar/decrypt-message message key symbols)))]
|
||||||
(-> (new FrequencyAnalyzer ciphertext symbols letter-frequences decrypt)
|
(-> (new FrequencyAnalyzer ciphertext symbols letter-frequencies-string decrypt)
|
||||||
.crack)))
|
.crack)))
|
||||||
|
|
||||||
|
|||||||
+12
-2
@@ -1,7 +1,17 @@
|
|||||||
(ns cipher-analytical-machine.symbols.frequencies
|
(ns cipher-analytical-machine.symbols.frequencies
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
(def english-letter-frequences {
|
(defn map-to-string
|
||||||
|
"Convert the map of frequencies to the frequency string. Letters are sorted by frequency in descending order."
|
||||||
|
[frequency-map]
|
||||||
|
(->> frequency-map
|
||||||
|
(reduce (fn [acc el] (conj acc el)) [])
|
||||||
|
(sort-by last)
|
||||||
|
(map first)
|
||||||
|
(reverse)
|
||||||
|
(apply str)))
|
||||||
|
|
||||||
|
(def english-letter-frequencies {
|
||||||
\a 0.0804
|
\a 0.0804
|
||||||
\b 0.0154
|
\b 0.0154
|
||||||
\c 0.0306
|
\c 0.0306
|
||||||
@@ -30,7 +40,7 @@
|
|||||||
\z 0.0009
|
\z 0.0009
|
||||||
})
|
})
|
||||||
|
|
||||||
(def ukrainian-letter-frequences {
|
(def ukrainian-letter-frequencies {
|
||||||
\а 0.064
|
\а 0.064
|
||||||
\б 0.013
|
\б 0.013
|
||||||
\в 0.046
|
\в 0.046
|
||||||
@@ -7,12 +7,14 @@ public class FrequencyAnalyzer {
|
|||||||
private String ciphertext;
|
private String ciphertext;
|
||||||
private int key;
|
private int key;
|
||||||
private String symbols;
|
private String symbols;
|
||||||
|
private String symbol_frequences;
|
||||||
private Decrypted decryptor;
|
private Decrypted decryptor;
|
||||||
|
|
||||||
public FrequencyAnalyzer(String ciphertext, String symbols, Map<Character, Double> symbol_frequences, Decrypted decryptor) {
|
public FrequencyAnalyzer(String ciphertext, String symbols, String symbol_frequences, Decrypted decryptor) {
|
||||||
this.ciphertext = ciphertext;
|
this.ciphertext = ciphertext;
|
||||||
this.key = 1;
|
this.key = 1;
|
||||||
this.symbols = symbols;
|
this.symbols = symbols;
|
||||||
|
this.symbol_frequences = symbol_frequences;
|
||||||
this.decryptor = decryptor;
|
this.decryptor = decryptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
(ns cipher-analytical-machine.symbols.frequencies-test
|
||||||
|
(:require
|
||||||
|
[clojure.test :refer :all]
|
||||||
|
[cipher-analytical-machine.symbols.frequencies :refer :all]))
|
||||||
|
|
||||||
|
(deftest calculate-char-index-test
|
||||||
|
(let [symbol-map english-letter-frequencies]
|
||||||
|
(testing "The map must be converted to 'etaoinsrhldcumfpgwybvkxjqz'"
|
||||||
|
(is (= "etaoinsrhldcumfpgwybvkxjqz"
|
||||||
|
(map-to-string symbol-map))))))
|
||||||
|
|
||||||
Reference in New Issue
Block a user