-
Notifications
You must be signed in to change notification settings - Fork 0
/
decrypt_vigenere_test.clj
executable file
·33 lines (25 loc) · 1.1 KB
/
decrypt_vigenere_test.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(ns set1.decrypt-vigenere-test
(:require [clojure.java.io :as io]
[clojure.test :refer :all]
[set1
[decrypt-vigenere :refer [decrypt-vigenere]]
[repeating-xor :as v]]
[util
[random :as random]
[tools :as u]]))
(defn decrypt-cipher
[ciphertext]
(clojure.string/join (map char (decrypt-vigenere ciphertext))))
(def ciphertext (with-open [rdr (io/reader (io/file (io/resource "set1/vigenere_ciphertext.txt")))]
(u/base64-to-byte' (apply concat (line-seq rdr)))))
(def plaintext (slurp (io/resource "set1/vigenere_plaintext.txt")))
;; Tests
(deftest ^:parallel decrypt-vigenere-test
(testing "Failed decryption of vigenere cipher"
(is (= plaintext (decrypt-cipher ciphertext)))))
#_
(deftest ^:parallel encrypt-and-decrypt-corpus
(testing "Failed decryption of vigenere cipher"
(let [plaintext (map int (slurp (io/resource "plaintext1.txt")))
cipher-key (map int (random/string (+ 2 (rand-int 39))))]
(is (= plaintext (decrypt-vigenere (v/encrypt plaintext cipher-key)))))))