CSE 2010: Asgn #3, Substitution Cipher (Again)

Due: Monday, 25 May 2009 (midnight)

The Task

Write a class Caesar with public instance methods String encode(String plain) and String decode (String encrypt) to implement a substitution cipher. Include a static main method to read from the standard input and encode or decode the input with a random cipher.

In a substitution cipher we have a list of characters or letters to encode. Each letter in the plain text which is found in the list is translated by a fixed number of places to the character some later in the list. (Characters at the end of the list are wrapped around---translated to a character in the front of the list.) Decoding is the inverse function. Characters not in the list are not encoded/decoded.

Input/Output

The Caesar program takes input from the command line and from the standard input stream. The first command-line argument is the command "encode" or "decode". The second command-line argument is the string of letters to encrypt. Each character appears only once in the string. The third command-line argument is the seed for the random-number generator. These arguments establish the substitution cipher to use. Use the random seed to find the number, between zero and the length of the list, to use in translating the characters, i.e., if there are n characters in the alphabet, then randomly select an integer 0≤s< n to shift.

For example, the command line

java Caesar encode ABCDEFGabcdefg 21387645
will transform the input
We the People of the United States, in Order to form a more perfect
Union, establish Justice, insure domestic Tranquility, provide for the
common defence, promote the general Welfare, and secure the Blessings
of Liberty to ourselves and our Posterity, do ordain and establish
this Constitution for the United States of America.
to the output
Wf thf Pfoplf og thf Unitfe Stbtfs, in Orefr to gorm b morf pfrgfdt
Union, fstbclish Justidf, insurf eomfstid Trbnquility, provief gor thf
dommon efgfndf, promotf thf Afnfrbl Wflgbrf, bne sfdurf thf ClfssinAs
og Licfrty to oursflvfs bne our Postfrity, eo orebin bne fstbclish
this Donstitution gor thf Unitfe Stbtfs og Bmfridb.

Notice the command

java Caesar encode ABCDEFGabcdefg 21387645 < Caesar.java | java Caesar decode ABCDEFGabcdefg 21387645
will encode and then decode the text resulting in the original input.

Helpful Stuff

Turning it in

Turn in the Java source code for the program using the submission server. The file name should be Caesar.java and the project is asgn03. Be sure your name is in comments at the beginning of your program as required in the standard header for this class. For your convenience, here is a submission form for this assignment.

File 1
Control code:
Course=cse2010
Project=asgn03


Ryan Stansifer <ryan@cs.fit.edu>
Last modified: Mon May 25 15:27:03 EDT 2009