Skip to content

Commit f1c953d

Browse files
committed
made some pytests
1 parent becfd07 commit f1c953d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

ciphers/break_vigenere.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import math
2+
13
LETTER_FREQUENCIES_DICT = {
24
"A": 8.12,
35
"B": 1.49,
@@ -216,7 +218,20 @@ def find_key_from_vigenere_cipher(ciphertext: str) -> str:
216218
# print(key)
217219

218220

219-
220221
# ---------- TESTS ----------
221-
# def test_index_of_coincidence(f)
222+
223+
class Test:
224+
def test_index_of_coincidence(self):
225+
ic = index_of_coincidence({'a': 50, 'b': 50}, 50)
226+
assert math.isclose(ic, 2.0)
227+
228+
def test_calculate_indexes_of_coincidence(self):
229+
ciphertext = "hellothere"
230+
result = calculate_indexes_of_coincidence(ciphertext, 2)
231+
assert result == [0.1, 0.3]
232+
233+
def test_friedman_method(self):
234+
ciphertext = "asqsfdybpypvhftnboexqumfsnglmcstyefv"
235+
result = friedman_method(ciphertext, 5)
236+
assert result == 3
222237

0 commit comments

Comments
 (0)