@@ -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 (uppercase text)
93
+ :param ciphertext: a string (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 (uppercase text)
147
+ :param ciphertext: a string (text)
148
148
:param key_length: a supposed length of the key
149
149
:return: the key as a string
150
150
"""
@@ -190,12 +190,7 @@ 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
-
196
193
"""
197
- # clean the ciphertext so that it only contains uppercase letters with no
198
- # punctuation, spaces etc.
199
194
clean_ciphertext_list = []
200
195
for symbol in ciphertext .upper ():
201
196
if symbol in LETTERS :
@@ -213,9 +208,13 @@ def find_key_from_vigenere_cipher(ciphertext: str) -> str:
213
208
214
209
215
210
if __name__ == "__main__" :
216
- print ()
211
+ print ("" )
217
212
# # how to execute
218
213
# with open("out.txt") as file:
219
214
# ciphertext = file.read()
220
215
# key = find_key_from_vigenere_cipher(ciphertext)
221
216
# print(key)
217
+
218
+
219
+ # ---------- TESTS ----------
220
+ # def test_index_of_coincidence(f)
0 commit comments