Hacking Secret Ciphers with Python

(Ann) #1
Chapter 21 – Hacking the Vigenère Cipher 355

vigenereHacker.py


  1. SILENT_MODE = False # if set to True, program doesn't print attempts


While your computer can perform calculations very fast, displaying characters on the screen is
relatively slow. If you want to speed up your program, you can set SILENT_MODE to True so
that the program does not waste time printing information to the screen. On the downside, you
will not know how the program is doing until it has completely finished running.


Summary


Hacking the Vigenère cipher requires several detailed steps to follow. There are also many parts
where our hacking program could fail: perhaps the Vigenère key used for encryption was larger
in length than MAX_KEY_LENGTH, or perhaps the English frequency matching function got
inaccurate results because the plaintext doesn’t follow normal letter frequency, or maybe the
plaintext has too many words that aren’t in our dictionary file and isEnglish() doesn’t
recognize it as English.


If you identify different ways that the hacking program could fail, you could change the code to
become ever more sophisticated to handle these other cases. But the hacking program in this book
does a pretty good job at reducing billions or trillions of possible keys to brute-force through to
mere thousands.


However, there is one trick to make the Vigenère cipher mathematically impossible to break, no
matter how powerful your computer or how clever your hacking program is. We’ll learn about
these “one-time pads” in the next chapter.

Free download pdf