CS414 Fall 2017 Program #6

Due: Monday, April 17th, 2017.
Late penalties: Tue: -5%, Wed, Thu, Fri, Sat, Sun: -10%, Mon -20%

Goals

This assignment builds or expands the following skills:

Before You Begin:

When You Are Done:

To turn your work in, go to mycourses.unh.edu, find CS414, and find the assignment. Then click "Submit Assignment" to upload your main file, cryptogram.py, plus any other files you have created.

I am providing you with a very minimal skeleton to get you going: cryptogram.py .

I am also providing you with a file with quotes for the game: quotes.txt .

Cryptograms

Encryption converts readable information (the plaintext) into unreadable information (the cyphertext). There are many encryption algorithms, but the simplest is a substitution cypher. In a substitution cypher, there is a mapping between letters in the plaintext and letters in the cyphertext.

The Caesar cypher is the simplest substitution cypher (Julius Caesar used it). Each letter in the plaintext is replaced with the letter 3 spaces after it in the alphabet:

plaintext letter cyphertext letter
A D
B E
C F
D G
... ...
V Y
W Z
X A
Y B
Z C
Thus the plaintext BABY WAX is mapped to the cyphertext EDEB ZDA. Notice that in a substitution cypher a given letter in the plaintext (e.g., B) is always replaced the same way (in this case E).

Usually substitution cyphers don't simply shift a letter forward in the alphabet, as the caesar cypher does; the replacement from plain letter to cypher letter is usually more arbitrary.

Cryptanalysis

Substitution cyphers are easy to break, if the cyphertext is long enough, because some letters occur more frequently. All we need is to count the frequency of letters in the cyphertext, and make some educated guesses. This is possible because English uses some letters much more often than others. In fact, the most common letters in English text are E, T, A, O, I, N, in order of decreasing frequency. Also, some letter pairs and triples occur very frequently. For example, if we are given a three-letter word QXW, and we have guessed that T maps to Q and W maps to E, we should then guess that X maps to H, because the triple THE is very frequent in English text.

Your Task

Write a program, called cryptogram.py, which does the following:

The program should interact with the user as follows:

Functions you should write

Break your work into parts, using functions. Here are some functions you could include in your program. Notice that many of these functions use a list of single letters, rather than a string. You can't replace individual letters in a string (strings are immutable), but you can replace entries in a list.