MP3: CaesarCipher

Introduction

Your program will do the following:

Details:

For example, if the input is:A-C E'? 099A ", then the output should be (each count should be on a separate line):

Text?
A-C E'? 099A "
A:2
C:1
E:1
DIGITS:3
SPACES:3
PUNCTUATION:3

Example output for input:2B @# OR NOT(2B)!

Text?
2B @# OR NOT(2B)!
B:2
N:1
O:2
R:1
T:1
DIGITS:2
SPACES:3
PUNCTUATION:1

See the unit test for definitive output examples.

Useful Hints

In this exercise, you are responsible for keeping tracking of the frequencies of letters, digits, spaces and punctuations. Luckily, statisticians have a tool for this, a histogram. You might want to use a bunch of integers to keep track of how many times each of the following comes up, but then you would need about 30 different integers.

Your code might then look the following:

Wrong Way To Do This Assignment

//UIUC CS125 FALL 2013 MP. File: CipherBreaker.java, CS125 Project: Challenge3-TopSecret, Version: 2013-09-21T10:53:54-0500.081308382
/**
 * See CipherBreaker.txt for instructions. TODO: add your netid to the line
 * below
 * 
 * @author bschong2
 */
public class CipherBreaker {
 
    public static void main(String[] args) {
        int numAs;
        int numBs;
        int numCs;
        ...
        int numDigits;
        int numSpaces;
        int numPunctuations;
         
        //Bunch of code to read in the input and increment each character accordingly.
        TextIO.putln("A: "+numAs);
        TextIO.putln("B: "+numBs);
        TextIO.putln("C: "+numCs);
        ...
        TextIO.putln("numDigits: "+numDigits);
        TextIO.putln("numSpaces: "+numDigits);
        TextIO.putln("numPunctuations: "+numPunctuations);
    }
}

Notice how the above is very cumbersome and easy to mess up. Instead, use the knowledge of arrays to make your life easier. By having a bunch of ints, you can create a single array of integers to store your frequency. Your code should then look like the following:

Right Way To Do This Assignment

//UIUC CS125 FALL 2013 MP. File: CipherBreaker.java, CS125 Project: Challenge3-TopSecret, Version: 2013-09-21T10:53:54-0500.081308382
/**
 * See CipherBreaker.txt for instructions. TODO: add your netid to the line
 * below
 * 
 * @author bschong2
 */
public class CipherBreaker {
 
    public static void main(String[] args) {
        int[] letterHistogram = new int[26];
        int numDigits;
        int numSpaces;
        int numPunctuations;
         
        //Bunch of code to read in the input and increment each character accordingly.
        for(int i=0;i<26++){
            //Print out the frequency of each letter.
        }
        TextIO.putln("numDigits: "+numDigits);
        TextIO.putln("numSpaces: "+numDigits);
        TextIO.putln("numPunctuations: "+numPunctuations);
    }
}

You will need to figure out how to manage your array. The following may prove useful for finding a one to one mapping between a character and an index to your integer array.