Hacking Secret Ciphers with Python

(Ann) #1
Chapter 7 – Hacking the Caesar Cipher with the Brute Force Technique 89

Figure 7-1. Auguste Kerckhoffs
January 19, 1835 - August 9, 1903

Figure 7-2. Claude Shannon
April 30, 1916 - February 24, 2001
“A cryptosystem should be secure even if
everything about the system, except the key, is
public knowledge.”

“The enemy knows the system.”

The Brute-Force Attack


Nothing stops a cryptanalyst from guessing one key, decrypting the ciphertext with that key,
looking at the output, and if it was not the correct key then moving on to the next key. The
technique of trying every possible decryption key is called a brute-force attack. It isn’t a very
sophisticated hack, but through sheer effort (which the computer will do for us) the Caesar cipher
can be broken.


Source Code of the Caesar Cipher Hacker Program


Open a new file editor window by clicking on File ► New Window. Type in the following code
into the file editor, and then save it as caesarHacker.py. Press F5 to run the program. Note that
first you will need to download the pyperclip.py module and place this file in the same directory
as the caesarHacker.py file. You can download this file from http://invpy.com/pyperclip.py.


Source code for caesarHacker.py




  1. Caesar Cipher Hacker




  2. http://inventwithpython.com/hacking (BSD Licensed)





  3. message = 'GUVF VF ZL FRPERG ZRFFNTR.'

Free download pdf