During this lab, you will create and hand in 1 file:
This week, we'll actually do the work of decoding a relatively simple encryption algorithm called a Caesar Cipher. (Actually reading through this wikipedia page will help you understand the assignment!)
Decoding a Caesar Cipher without a key requires that you know the relative frequencies of letters in the alphabet so that you can make the best guess possible. Last week you figured out how frequently letters appear in the English language based on large bodies of English text; this week, you'll be using those frequencies to make an educated guess at decrypting a file.
Because we know the message was encoded using a rotation of the alphabet (e.g. A = B, B = C, etc), we can narrow down the 403291461126605635584000000 possible substitution ciphers to a mere 26 rotations, and just check all of those to see which one fits best.
Your program will take as input an encoded file, and write the decrypted file.
If you choose to use text files and calculate your own frequencies, your input files will be the same as last week.
If you choose to use a frequencies list rather than calculating your own, the input file will look like this. (These frequencies may look different from your calculated frequencies from last week, but they have the same relative scale and should give you similar output.)
I've also worked up a few simple coded messages for you:
Using The Federalist Papers by Alexander Hamilton in the books directory:
Path to a file to parse: books/federalist.txt Path to an encoded message: message1.txt File output.txt written.
Using a frequencies file in my current working directory:
Path to a frequencies file: freq.txt Path to an encoded message: message1.txt File output.txt written.
The output.txt for both of these runs should look the same.
The biggest challenge of this program will be translating from one alphabet rotation to another. You'll want to do a lot of math with letters, so familiarize yourself with ord() and its friend, chr().
>>> ord('A') 65 >>> chr( ord('A') + 2 ) 'C'
You still have a choice of data structures here (list or dictionary), so the precise combination of these functions will be unique to your implementation. Use lots of print statements, and make sure you're calculating what you mean to be calculating!
Once again, some of your program points will come from commenting your code.
As usual, you'll be handing in your lab work via the course Learn@UW dropboxes. Navigate to our 301 course page, and click the Dropbox link in the top navigation bar. You should see a dropbox for Program 11 - this is where you should hand in your decipher.py file.
Note that the dropbox will close at noon on 21 April, so be sure to submit your files before then.