CIT 591 Assignment 6: Cryptograms
Fall 2013, David Matuszek

Purposes of this assignment

General idea of the assignment

There are two parts to this assignment:

Don't have one of you do the easy part and the other do the hard part. Work with your partner on both parts!

Possible resources

If you are unfamiliar with cryptograms, Wikipedia has a reasonable explanation, and you can try some out at Puzzle Baron's (just hit the Play button; but don't get too involved!).


You need a source of quotes to encode/decode. You can find over 9000 of them at One-Line Aphorisms (Fortunes) File. Get the raw text file from there, and discard the category codes (the first two characters of each line).

Word and frequency lists

There are many lists of English words on the Internet; some of them are sorted by frequency. The 6,000 most frequently used English words is interesting primarily because it's easy to copy and paste the words into a text file (you might not want to use all 6000; or, you might want to use just the first 1000, plus some other list that isn't sorted by frequency). Or perhaps you can find better lists.

There are lists of letter frequencies, bigram and trigram frequencies, and a few similar things, at this page at Puzzle Baron's Cryptograms.


The latest release appears to be scalatest_2.10-2.0.RC1.jar. If you are using a scalatest_2.10-1.9something jar, you should replace it--the newer version is really much more convenient to use. (I've been using M8 rather than RC1; so far I haven't seen any differences.) In Eclipse you can go to Project → Properties → Java Build Path → Libraries where you can use the Remove and Add External Jars buttons to replace the version of Scalatest that you are using.

Detailed specification

Use TDD (Test-Driven Development). Every method* you write should be unit tested!

I'd like to place as few restrictions as possible on you for this assignment, but I'd also like to be able to run my own unit tests. So I'll ask you to name your project Cryptograms, use a package cryptograms, and in the package have an object Dave containing the following methods:

def encode(plainText: String, code: String): String
Encodes the plainText message and returns the coded message. Encoding means replacing each 'A' in the message with the first letter in the code, each 'B' with the second letter in the code, etc. The code should be exactly 26 letters long. No letter should be encoded as itself. Before doing anything else, all lowercase letters in the arguments should be replaced by the corresponding uppercase letters. Non-letters should be unchanged.
def decode(encodedText: String, code: String): String
This method is the inverse of encode: The 26-letter code String is used in the "opposite direction." What is encoded with a given code can be decoded with the same code. Also, the decode method can assume neither the encodedText nor the code contains any lowercase letters.
def discoverCode(message: String): String
Given a cryptogram, tries to determine the code that was used. The return value should be a String consisting of exactly 26 uppercase letters. If the cryptogram (encoded message) and the return value are given to the decode method, the result should be the original, plain-text message (or as close to it as possible).

The Dave object may contain helper methods used only within this object, but it should not contain any methods needed by the rest of the program. The entire purpose of Dave is to give me an "entry" into your code. Your program should not depend in any way on the presence of this object.

Write a separate DaveTest class to test the methods in Dave.

*You may have methods whose sole purpose is to do input and/or output, and such methods need not be tested. However, when running unit tests, no output should be produced nor input expected.

Due date

Submit your team's program, as a single .zip file, to Canvas by 6am Friday, October 18. Decide which of you is going to turn in the assignment, and make only one submission for the two of you. Make sure both of your names are in comments at the top of each file.