Skip to content

Commit 6134fa1

Browse files
committed
made index of coincidence
1 parent 851fc3e commit 6134fa1

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

ciphers/break_vigenere.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
99

1010

11+
def index_of_coincidence(frequencies: dict, length: int) -> float:
12+
"""
13+
Calculates the index of coincidence for a text.
14+
:param frequencies: dictionary of the form {letter_of_the_alphabet: amount of times it appears in the text as a percentage}
15+
:param length: the length of the text
16+
:return the index of coincidence:
17+
"""
18+
index = 0.0
19+
for value in frequencies.values():
20+
index += (value/length)**2
21+
return index
22+
23+
1124
def find_key_from_vigenere_cipher(ciphertext: str) -> str:
1225
clean_ciphertext = list()
1326
for symbol in ciphertext:

requirements.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)