Programming Assignment #2: The Skip Cipher
Due Date: Monday, May 1, 2006


The Skip Cipher

In a skip cipher a message is encrypted by inserting a number, N, of random characters before and after every character in the original message. The number N, which determines how many random characters are inserted, is the cryptographic key for this cipher. In order to decrypt messages encrypted with this cipher, it is necessary to know N. To decrypt a message that was encrypted by a skip cipher, you would remove N characters between every two letters.

For N=3, the following example shows how the skip cipher works:

Plaintext Message: this is a test
       Ciphertext: BYMtXYZhMBDiPPZsJREiVCYsWENaFGAtUIEeOIHsPOStFOO

The plaintext message is enciphered by inserting 3 random characters (shown here for illustrative purposes in UPPERCASE) between each pair of letters in the message. Note that the spaces have been removed from the message. To decrypt the message, given N, you would just remove N characters between the first character and the N+1st, and so on.


Click here for an Applet Demo.

Part 1. Implementing a Skip Cipher

You will implement this skip cipher by defining and implementing the SkipCipher class as a subclass of the Cipher class, which is described in Section 8.5 of Java, Java, Java. Use the design of the Caesar and Transpose classes as your models.

See the UML diagram in Figure 8-13 on page 369 and the implementation of the Cipher class on page 371. Recall that the encrypt() and decrypt methods are fully implemented in the Cipher class. These methods can be used, unchanged, by any objects of any Cipher subclasses, including your SkipCipher class.

Note that the encrypt() and decrypt() methods call the encode() and decode() methods. These methods are left abstract in the Cipher class and must be given implementations in your SkipCipher subclass.

Thus, your SkipCipher class should implement the encode() and decode methods, plus whatever supplementary methods you might need. It should have a constructor method that allows the user to set the value of its key (N).

The SkipCipher.encode() method should insert N random characters between every two characters in the text. The decode() method should remove N characters between the first and N+1st letters in the encrypted message, and so on. The variable N should be an instance variable of your SkipCipher class.

User Interface

Design and implement a user interface and use it to test your skip cipher. You can use an applet interface. The interface must meet the following specifications:

Design and Style Specifications

Your program should make appropriate use of the design and style principles we have been stressing all semester. This would include the proper use of methods and parameters, variable names, the public and private portions of a class. The proper documentation conventions should be followed. You should thoroughly test that your program works correctly and is easy to use.

Evaluation Criteria. Your program will be evaluated on the following basis:

Optional Challenge

For an optional challenge, you might want to consider developing a SkipCipherAnalyzer, a program that can automatically break a skip cipher without knowing the skip size. See here for details.

Hand In Instructions

Hand in hard copy of your source programs -- your .java files -- on the due date. Upload a copy of your source programs (NOT your .class files) using Blackboard's digital drop box.

PLAGIARISM: READ THIS CAREFULLY!

This is an individual or partner programming project. You may choose to work on it completely by yourself or with 1 other classmate as your partner. If you choose to work alone, it is expected that the work you submit will be your work entirely. If you choose to work with a partner, then the work you submit should be done entirely by you and your partner and who did what must be documented in the initial comment in the program. In this case a single copy of the program can be handed in. If you feel you can write the program by yourself, you should do so since that will probably give you the most effective learning experience.
This does not mean that you cannot talk to classmates about your work. It is okay to discuss in general how you are tackling a particular problem -- e.g., "I used a String to store the value input by the user." You may also give help to or receive help from a classmate about a particular error message or program bug. "That error means you must have forgotten a semicolon."

However, you may not copy another person's code or solution, whether from a classmate or from someone who took the course before or from someone you find on the Internet, in whole or in part, either by hand or electronically, and submit it as your own. If you need help with either design or programming, you should consult with the Instructors or TAs or with the CPSC Study Hall Consultants. If you receive substantial help from another student or a TA or an Instructor, you must document it in your program's header by providing the name of the person who helped you and a brief description of the type of help you received. Getting help on an assignment and not documenting it is a form of plagarism.