Compare commits

..
5 Commits
Author SHA1 Message Date
KKlochko 77efa81c54 Add the Gitlab CI/CD configuration.
continuous-integration/drone/push Build is passing
2023-10-09 20:00:50 +03:00
KKlochko 51609b1d27 Add the clojure wrapper for the frequency analizer and its test.
continuous-integration/drone/push Build is passing
2023-10-05 20:10:05 +03:00
KKlochko 40af8401b2 Add a frequency analyzer as a stub. 2023-10-05 20:08:41 +03:00
KKlochko 0a87ab9e91 Add the Caesar decrypted interface for Java. 2023-10-05 20:07:43 +03:00
KKlochko 9c1a8b1bae Add the java source path. 2023-10-05 20:07:11 +03:00
6 changed files with 61 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
image: clojure:temurin-11-lein-2.10.0-alpine
stages:
- test
unit tests:
stage: test
script:
- lein test
+1
View File
@@ -8,6 +8,7 @@
[org.apache.tika/tika-core "1.28.5"] [org.apache.tika/tika-core "1.28.5"]
[org.apache.tika/tika-langdetect "1.28.5"]] [org.apache.tika/tika-langdetect "1.28.5"]]
:main ^:skip-aot cipher-analytical-machine.core :main ^:skip-aot cipher-analytical-machine.core
:java-source-paths ["src/main/java"]
:target-path "target/%s" :target-path "target/%s"
:profiles {:uberjar {:aot :all :profiles {:uberjar {:aot :all
:jvm-opts ["-Dclojure.compiler.direct-linking=true"]}}) :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})
@@ -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)))
@@ -0,0 +1,23 @@
package cipher_analytical_machine.analizers.caesar;
import cipher_analytical_machine.ciphers.caesar.Decrypted;
import java.util.Map;
public class FrequencyAnalyzer {
private String ciphertext;
private int key;
private String symbols;
private Decrypted decryptor;
public FrequencyAnalyzer(String ciphertext, String symbols, Map<Character, Double> symbol_frequences, Decrypted decryptor) {
this.ciphertext = ciphertext;
this.key = 1;
this.symbols = symbols;
this.decryptor = decryptor;
}
public String crack() {
return decryptor.decrypt(ciphertext, key, symbols);
}
}
@@ -0,0 +1,6 @@
package cipher_analytical_machine.ciphers.caesar;
public interface Decrypted {
String decrypt(String message, int key, String symbols);
}
@@ -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))))))