Chapter 13 – Hacking the Transposition Cipher 187
HACKING THE TRANSPOSITION
CIPHER
Topics Covered In This Chapter:
Multi-line Strings with Triple Quotes
The strip() String Method
To hack the transposition cipher, we will use a brute-force approach. Of the thousands of keys,
the correct key is most likely that only one that will result in readable English. We developed
English-detection code in the last chapter so the program can realize when it has found the correct
key.
Source Code of the Transposition 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 transpositionHacker.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 transpositionHacker.py file. You can download this file from
http://invpy.com/pyperclip.py.
Source code for transpositionHacker.py
Transposition Cipher Hacker
http://inventwithpython.com/hacking (BSD Licensed)
- import pyperclip, detectEnglish, transpositionDecrypt