Project 8: GUIs

The goal of this project is to compose your own program using Java's GUI packages. You will make use of your Caesar cipher algorithm from Project

1. Introduction

You are a programmer for the ancient Gauls who are being opressed by Roman invaders under Julius Caesar. The Romans, of course, are using the Caesar cipher, invented by their general. Your spies are able to intercept much of the Roman communication, but you do not have any of the keys (ie, the number of letters to shift).

You are commissioned to write a program that will decrypt any message, even if you don't have the key. The idea is that there are only 26 possible keys (because if you shift the message any more than 26 positions, then it simply wraps around; shifting the message 27 characters is the same as shifting it 1). You will write a program that will allow a user to shift a message back and forth until an intelligible message appears.

2. A Decoder Program

Write a program that works as follows:

For example, if the text the user enters is "My name is Vercingetorix", pressing the ">" button will change the text to "Nz obnf jt Wfsdjohfupsjy." Pressing ">" again will change the text to "Oa pcog ku Zgtekpigvqtkz." Pressing "<" will return it to "Nz obnf jt Wfsdjohfupsjy." If you restart the program and enter "Nz obnf jt Wfsdjohfupsjy" and click "<" once or click ">" 25 times, you will get the decoded message "My name is Vercingetorix."

3. Tips and Hints

Remember, the program will have two windows. The action listener for the "enter" button on the first window must do a lot of things. First, it must set the original window to no longer be visible (setVisible(false)). Then it must create the second window, add all the components, attach action listeners to the "<" and ">" buttons, etc. Think carefully about what each action listener class's instance variables need to be. What components does it need to be able to communicate with?

Although what was covered in class should be enough to complete this project, feel free to experiment with other things from the textbook and the Java API to improve the appearance of your program.

4. Testing

Use your program to decrypt the following messages sent over the front lines:

5. Extra credit

Although this description doesn't say it explicitly, the most straightforward way to implement this would be for the second window initally to have the text the user typed in, since the user has not asked for any shifting yet. However, your program could make use of known facts about letter and word frequencies in English to make an initial guess. For example, "e" is the most frequently occurring letter in English; therefore, if "g" is the most frequently occurring letter in the encrypted text, you might guess that the message is shifted ahead two characters, and make an initial guess by shifting it back two characters.

For more information on letter and word frequency cryptanalysis of substitution ciphers, see Sir Arthur Conan Doyle, "The Adventure of the Dancing Men" and Edgar Allan Poe, "The Gold Bug."

DUE: Thurs, Dec 7, at 5:00 PM.

ALSO: No project will be accepted later than Fri, Dec 8, at 5:00 PM, even if you have two late days left.


Thomas VanDrunen
Last modified: Tue Nov 28 08:24:05 CST 2006