Compare commits

...
2 Commits
Author SHA1 Message Date
KKlochko ac2cf2ac58 Fix the bug that the default language symbols override the symbols.
continuous-integration/drone/push Build is passing
2023-10-13 21:46:48 +03:00
KKlochko 043257bb64 Update the FrequencyAnalyzer to use the frequency string instead.
continuous-integration/drone/push Build is passing
2023-10-12 22:10:41 +03:00
4 changed files with 10 additions and 6 deletions
@@ -50,10 +50,10 @@
(defn frequency-analizer-get-plaintext
"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
(decrypt [this 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)))
+4 -2
View File
@@ -122,8 +122,10 @@
(defn set-symbols
"Set defaults symbols for a language."
[options]
(set-option options :symbols
(sf/default-symbol-factory (:language options))))
(if (contains? options :language)
(set-option options :symbols
(sf/default-symbol-factory (:language options)))
options))
(defn load-and-set-option
"Load the option and set it."
@@ -7,12 +7,14 @@ public class FrequencyAnalyzer {
private String ciphertext;
private int key;
private String symbols;
private String symbol_frequences;
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.key = 1;
this.symbols = symbols;
this.symbol_frequences = symbol_frequences;
this.decryptor = decryptor;
}
@@ -79,7 +79,7 @@
ciphertext "bca"
key 1
symbols "abc"
frequencies sf/english-letter-frequencies]
frequencies "etaoinsrhldcumfpgwybvkxjqz"]
(testing "The ciphertext is 'bca' and key is 1."
(is (= plaintext
(frequency-analizer-get-plaintext ciphertext symbols frequencies))))))