@@ -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 (text)
93+ :param ciphertext: a string (uppercase 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 (text)
147+ :param ciphertext: a string (uppercase text)
148148 :param key_length: a supposed length of the key
149149 :return: the key as a string
150150 """
@@ -190,7 +190,12 @@ 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+
193196 """
197+ # clean the ciphertext so that it only contains uppercase letters with no
198+ # punctuation, spaces etc.
194199 clean_ciphertext_list = []
195200 for symbol in ciphertext .upper ():
196201 if symbol in LETTERS :
@@ -208,15 +213,9 @@ def find_key_from_vigenere_cipher(ciphertext: str) -> str:
208213
209214
210215if __name__ == "__main__" :
211- print ("" )
216+ print ()
212217 # # how to execute
213218 # with open("out.txt") as file:
214219 # ciphertext = file.read()
215220 # key = find_key_from_vigenere_cipher(ciphertext)
216221 # print(key)
217-
218-
219-
220- # ---------- TESTS ----------
221- # def test_index_of_coincidence(f)
222-
0 commit comments