Skip to content

Commit 38f770c

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # ciphers/break_vigenere.py
2 parents 4c9f042 + f31a4e6 commit 38f770c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

ciphers/break_vigenere.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def friedman_method(ciphertext: str, max_keylength: int | None = None) -> int:
9090
page: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher The algorithm
9191
is in the book "Introduction to Cryptography", K. Draziotis
9292
https://repository.kallipos.gr/handle/11419/8183
93-
:param ciphertext: a string (uppercase text)
93+
:param ciphertext: a string (text)
9494
:param max_keylength: the maximum length of key that Friedman's method
9595
should check, if None then it defaults to the length of the cipher
9696
:return: the length of the key
@@ -144,7 +144,7 @@ def find_key(ciphertext: str, key_length: int) -> str:
144144
to a letter of the key. The whole procedure takes place for every letter
145145
of the key (essentially as many times as the length of the key). See
146146
here: https://www.youtube.com/watch?v=LaWp_Kq0cKs
147-
:param ciphertext: a string (uppercase text)
147+
:param ciphertext: a string (text)
148148
:param key_length: a supposed length of the key
149149
:return: the key as a string
150150
"""
@@ -190,12 +190,7 @@ def find_key_from_vigenere_cipher(ciphertext: str) -> str:
190190
Tries to find the key length and then the actual key of a Vigenere
191191
ciphertext. It uses Friedman's method and statistical analysis. It works
192192
best for large pieces of text written in the english language.
193-
IMPORTANT: Some trial and error might be needed to find the actual key
194-
especially by changing the value of MAX_KEYLENGTH.
195-
196193
"""
197-
# clean the ciphertext so that it only contains uppercase letters with no
198-
# punctuation, spaces etc.
199194
clean_ciphertext_list = []
200195
for symbol in ciphertext.upper():
201196
if symbol in LETTERS:
@@ -213,9 +208,13 @@ def find_key_from_vigenere_cipher(ciphertext: str) -> str:
213208

214209

215210
if __name__ == "__main__":
216-
print()
211+
print("")
217212
# # how to execute
218213
# with open("out.txt") as file:
219214
# ciphertext = file.read()
220215
# key = find_key_from_vigenere_cipher(ciphertext)
221216
# print(key)
217+
218+
219+
# ---------- TESTS ----------
220+
# def test_index_of_coincidence(f)

0 commit comments

Comments
 (0)