@@ -90,7 +90,7 @@ def friedman_method(ciphertext: str, max_keylength: int | None = None) -> int:
90
90
page: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher The algorithm
91
91
is in the book "Introduction to Cryptography", K. Draziotis
92
92
https://repository.kallipos.gr/handle/11419/8183
93
- :param ciphertext: a string (text)
93
+ :param ciphertext: a string (uppercase text)
94
94
:param max_keylength: the maximum length of key that Friedman's method
95
95
should check, if None then it defaults to the length of the cipher
96
96
:return: the length of the key
@@ -144,7 +144,7 @@ def find_key(ciphertext: str, key_length: int) -> str:
144
144
to a letter of the key. The whole procedure takes place for every letter
145
145
of the key (essentially as many times as the length of the key). See
146
146
here: https://www.youtube.com/watch?v=LaWp_Kq0cKs
147
- :param ciphertext: a string (text)
147
+ :param ciphertext: a string (uppercase text)
148
148
:param key_length: a supposed length of the key
149
149
:return: the key as a string
150
150
"""
@@ -190,7 +190,12 @@ def find_key_from_vigenere_cipher(ciphertext: str) -> str:
190
190
Tries to find the key length and then the actual key of a Vigenere
191
191
ciphertext. It uses Friedman's method and statistical analysis. It works
192
192
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
+
193
196
"""
197
+ # clean the ciphertext so that it only contains uppercase letters with no
198
+ # punctuation, spaces etc.
194
199
clean_ciphertext_list = []
195
200
for symbol in ciphertext .upper ():
196
201
if symbol in LETTERS :
@@ -208,15 +213,9 @@ def find_key_from_vigenere_cipher(ciphertext: str) -> str:
208
213
209
214
210
215
if __name__ == "__main__" :
211
- print ("" )
216
+ print ()
212
217
# # how to execute
213
218
# with open("out.txt") as file:
214
219
# ciphertext = file.read()
215
220
# key = find_key_from_vigenere_cipher(ciphertext)
216
221
# print(key)
217
-
218
-
219
-
220
- # ---------- TESTS ----------
221
- # def test_index_of_coincidence(f)
222
-
0 commit comments