226 http://inventwithpython.com/hacking
Email questions to the author: [email protected]
HACKING THE AFFINE CIPHER
Topics Covered In This Chapter:
The ** Exponent Operator
The continue Statement
We know that the affine cipher is limited to only a few thousand keys. This means it is trivial to
perform a brute-force attack against it. Open a new File Editor and type in the following code.
Save the file as affineHacker.py.
Source Code of the Affine 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 affineHacker.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 affineHacker.py file. You can download this file from http://invpy.com/pyperclip.py.
Typing the string for the myMessage variable might be tricky, but you can copy and paste it
from http://invpy.com/affineHacker.py to save time.
Source Code for affineHacker.py
Affine Cipher Hacker
http://inventwithpython.com/hacking (BSD Licensed)
- import pyperclip, affineCipher, detectEnglish, cryptomath
- SILENT_MODE = False