Add the IsNonsense interface for FrequencyAnalyzer.
continuous-integration/drone/push Build is failing
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
(ns cipher-analytical-machine.analyzers.caesar
|
(ns cipher-analytical-machine.analyzers.caesar
|
||||||
(:require [cipher-analytical-machine.ciphers.caesar :as caesar]
|
(:require [cipher-analytical-machine.ciphers.caesar :as caesar]
|
||||||
[clojure.string :as cs]
|
[clojure.string :as cs]
|
||||||
|
[cipher-analytical-machine.analyzers.language :as language]
|
||||||
[cipher-analytical-machine.analyzers.analyzers :as ca])
|
[cipher-analytical-machine.analyzers.analyzers :as ca])
|
||||||
(:import [cipher_analytical_machine.ciphers.caesar Decrypted]
|
(:import [cipher_analytical_machine.ciphers.caesar Decrypted]
|
||||||
|
[cipher_analytical_machine.analyzers.caesar IsNonsense]
|
||||||
[cipher_analytical_machine.analyzers.caesar FrequencyAnalyzer])
|
[cipher_analytical_machine.analyzers.caesar FrequencyAnalyzer])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
@@ -50,10 +52,13 @@
|
|||||||
|
|
||||||
(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-frequencies-string]
|
[ciphertext symbols letter-frequencies-string language-code]
|
||||||
(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-frequencies-string decrypt)
|
is-nonsense (reify IsNonsense
|
||||||
|
(isNonsense [this message]
|
||||||
|
(language/is-nonsense? message language-code)))]
|
||||||
|
(-> (new FrequencyAnalyzer ciphertext symbols letter-frequencies-string decrypt is-nonsense)
|
||||||
.crack)))
|
.crack)))
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,8 @@
|
|||||||
|
|
||||||
(= analyzer "Frequency")
|
(= analyzer "Frequency")
|
||||||
(caesar-analyzers/frequency-analizer-get-plaintext message symbols
|
(caesar-analyzers/frequency-analizer-get-plaintext message symbols
|
||||||
(symbol-frequencies/map-to-string frequencies)))))
|
(symbol-frequencies/map-to-string frequencies)
|
||||||
|
(:language options "en")))))
|
||||||
|
|
||||||
(defn cracking-actions
|
(defn cracking-actions
|
||||||
[options arguments action-type]
|
[options arguments action-type]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cipher_analytical_machine.analyzers.caesar;
|
package cipher_analytical_machine.analyzers.caesar;
|
||||||
|
|
||||||
|
import cipher_analytical_machine.analyzers.caesar.IsNonsense;
|
||||||
import cipher_analytical_machine.ciphers.caesar.Decrypted;
|
import cipher_analytical_machine.ciphers.caesar.Decrypted;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -11,12 +12,14 @@ public class FrequencyAnalyzer {
|
|||||||
private String symbols;
|
private String symbols;
|
||||||
private String symbol_frequences;
|
private String symbol_frequences;
|
||||||
private Decrypted decryptor;
|
private Decrypted decryptor;
|
||||||
|
private IsNonsense isNonsense;
|
||||||
|
|
||||||
public FrequencyAnalyzer(String ciphertext, String symbols, String symbol_frequences, Decrypted decryptor) {
|
public FrequencyAnalyzer(String ciphertext, String symbols, String symbol_frequences, Decrypted decryptor, IsNonsense isNonsense) {
|
||||||
this.ciphertext = ciphertext;
|
this.ciphertext = ciphertext;
|
||||||
this.symbol_frequences = symbol_frequences;
|
this.symbol_frequences = symbol_frequences;
|
||||||
this.symbols = symbols;
|
this.symbols = symbols;
|
||||||
this.decryptor = decryptor;
|
this.decryptor = decryptor;
|
||||||
|
this.isNonsense = isNonsense;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String crack() {
|
public String crack() {
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package cipher_analytical_machine.analyzers.caesar;
|
||||||
|
|
||||||
|
public interface IsNonsense {
|
||||||
|
boolean isNonsense(String message);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user