Cryptography is an ancient study of secret writing. There is a wealth of literature in this field. An extremely readable book on this subject is The Code Book by Simon Singh. This is a field of study that is of particular relevance in Computer Science. Given the widespread use of computers, one of the things people are interested in is making transactions over the internet more secure.
In this programming assignment we are trying to achieve two goals.
For the purposes of this programming assignment convert the message that you are asked to encode or decode to lower case. You will only be encoding or decoding the letters of the alphabet. Punctuation marks and numerals remain untouched.
Substitution Cipher: In this method you will replace the letters using the following scheme.
Plain Text: a b c d e f g h i j k l m n o p q r s t u v w x y z Cipher Text: q a z w s x e d c r f v t g b y h n u j m i k o l pSave the Cipher letters in an array of characters.
char[] cipher = { 'q', 'a', 'z', ...., 'o', 'l', 'p' };To find the substitution for the character d first convert d into an index for the array cipher as follows:
int idx = (int) ('d' - 'a');Then use that index (whose value in this case is 3) to access the character that will be a substitute for d (in this case cipher[3], which is w. The Caesar Cipher is also a substitution cipher that can be easily decoded.
Vigenere Cipher: Substitution ciphers can be broken by frequency analysis. To make the cipher more secure you can use two or more letters to encrypt. The Vignere cipher uses a pass phrase to encrypt and decrypt.
a b c d e f g h i j k l m n o p q r s t u v w x y z a a b c d e f g h i j k l m n o p q r s t u v w x y z b b c d e f g h i j k l m n o p q r s t u v w x y z a c c d e f g h i j k l m n o p q r s t u v w x y z a b d d e f g h i j k l m n o p q r s t u v w x y z a b c e e f g h i j k l m n o p q r s t u v w x y z a b c d f f g h i j k l m n o p q r s t u v w x y z a b c d e g g h i j k l m n o p q r s t u v w x y z a b c d e f h h i j k l m n o p q r s t u v w x y z a b c d e f g i i j k l m n o p q r s t u v w x y z a b c d e f g h j j k l m n o p q r s t u v w x y z a b c d e f g h i k k l m n o p q r s t u v w x y z a b c d e f g h i j l l m n o p q r s t u v w x y z a b c d e f g h i j k m m n o p q r s t u v w x y z a b c d e f g h i j k l n n o p q r s t u v w x y z a b c d e f g h i j k l m o o p q r s t u v w x y z a b c d e f g h i j k l m n p p q r s t u v w x y z a b c d e f g h i j k l m n o q q r s t u v w x y z a b c d e f g h i j k l m n o p r r s t u v w x y z a b c d e f g h i j k l m n o p q s s t u v w x y z a b c d e f g h i j k l m n o p q r t t u v w x y z a b c d e f g h i j k l m n o p q r s u u v w x y z a b c d e f g h i j k l m n o p q r s t v v w x y z a b c d e f g h i j k l m n o p q r s t u w w x y z a b c d e f g h i j k l m n o p q r s t u v x x y z a b c d e f g h i j k l m n o p q r s t u v w y y z a b c d e f g h i j k l m n o p q r s t u v w x z z a b c d e f g h i j k l m n o p q r s t u v w x y
Let us say we want to encrypt hello world and we use as our pass phrase seal. Here is how we would lay the phrases out. The pass phrase is repeated over and over again in order with the text that needs to be encrypted. The letter from the pass phrase marks the row and the letter from the plain text marks the column.
Pass Phrase: seals ealse Plain Text: hello world Encrypted Text: zilwg aocdh
To decrypt, we would reverse the process. Use the same pass phrase seal repeatedly with the encrypted text. This time, the letter from the pass phrase marks the column and the letter from the encrypted text marks the row.
Pass Phrase: seals ealse Encrypted Text: zilwg aocdh Plain Text: hello world
There are several classes that you will be writing for this assignment. But they will all be in one file called TestCipher.java. The template for your program is as follows:
interface Cipher { public String encode ( String str ); public String decode ( String str ); } class SubstitutionCipher implements Cipher { public String encode ( String str ) { ... } public String decode ( String str ) { ... } } class VigenereCipher implements Cipher { public String encode ( String str ) { ... } public String decode ( String str ) { ... } } public class TestCipher { public static void main ( String [] args ) { } }
Your TestCipher class will test the encoding and decoding methods of the two Cipher algorithms Your output will look something like this:
Substitution Cipher Enter Plain Text to be Encoded: hello world Encoded Text: dsvvb kbnvw Enter Encoded Text to be Decoded: dsvvb kbnvw Decoded Plain Text: hello world Vigenere Cipher Enter Plain Text to be Encoded: hello world Enter Pass Phrase (no spaces allowed): seal Encoded Text: zilwg aocdh Enter Encoded Text to be Decoded: zilwg aocdh Enter Pass Phrase (no spaces allowed): seal Decoded Plain Text: hello world
You will do an object oriented analysis and design for this problem, code and test your application. Use any class available in the standard Java library for your solution. The file that you will be turning in will be called TestCipher.java. The file will have a header of the following form:
/* File: TestCipher.java Description: Student's Name: Student's UT EID: Course Name: CS 313E Unique Number: 54070 Date Created: Date Last Modified: */
You will follow the standard Java Coding Conventions. You can either view the HTML page or download the PDF or Postscript and print it out. There is a modification that I would like to make to the standard coding conventions. Please align the opening and closing braces vertically so that you can easily make out the blocks of code.
Do this: if ( x > 5 ) { a = b + c; } Not this: if ( x > 5 ) { a = b + c; }
Use the turnin program to submit your TestCipher.java file. The TAs should receive your work by 5 PM on Saturday, 14 February 2009. We will be looking for clean logic and good documentation. There will be substantial penalties if you do not adhere to the guidelines.