Lab 7-2: Bruteforcing the Transposition Cipher, Revisited

Note: Part of this lab came from Al Sweigart’s great book, Hacking Secret Ciphers with Python: A beginner’s Guide to cryptography and computer programming with Python, available online here at Invent With Python, among his other works. Feel free to check them out if they interest you!

Lab Requirements and Specifications

This lab will be a modification on your previous 6-3 lab, FILN-brutetransposition.py. Copy and paste your code into a new file and name it FILN_brutetransposition2.py, where FILN is your first initial and last name, no space.

Similar to your brute forcing program from before, you’ll want to cycle through every key possibility. However, this time, every time you perform a decryption, you will also check to see if the decryption is English by using your detectEnglish.py program. The target percentage threshold to set is up to you!

This time, if it detects a decrypted message that resembles English, it should use input() to ask the user what to do (continue / end) - using input() will also pause program execution. If the user chooses to end the program, it should display the whole decrypted message, and then quit the program. If the user chooses to continue, then the program will simply continue decrypting with each key until it hits another English output or it ends.

Testing Your Program

Below is a sample output using the message:

"aeeeiywvyhhil  nnoiicoevwagdtuloh reasusarllokeay y i  epn dsi uncbnaoys fwpioettwogc h nd  hsusotomgeap   hdh a   swwlk"
Trying key #1: aeeeiywvyhhil  nnoiicoevwagdtuloh reasusarllokeay y i  ...
Trying key #2: aseie euinycwbvnyahohyisl  f wnpniooieitctoweovgwca ghd...
Trying key #3: aaterweloelgiocyk wehva yynh dhy i  lih  s  unesnpoonti...
Trying key #4: als eoi eh he usirnuyecswabovsntyuaohsomhaygirsell a lf...
Trying key #5: awy oea ftegywoed pmitiigyu oewl eavoetpyhpt h nw hr o ...
Trying key #6: acastgeoriweeel oaevlugpiwonc yakc  wgebh vdan hytyandh...
Trying key #7: aia   deisef hecupwh eosnpsaiea iu yvrdos wwlseo valitt...
Trying key #8: anlksp  enoeii  eoha ohhei yuesdiir ntuhyceycts woa bwo...
Trying key #9: a tlpyco enulns m enlo  hg eookdf esiiheswnawyi aipdpww...
Trying key #10: always code as if the guy who ends up maintaining your ...
Found potential solution with key 10, enter 'X' to exit or just press Enter to continue: X
Ending.  The selected key is 10
The selected solution is:
always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you liveadsgshk

The following space is provided in case you want to test code out or write it in the browser:

Next Section - Lab 7-3: Word Frequency Counter