Encryption Assignment

Don't make a nice user interface for this. I won't give you extra marks. Put it in a void main program.
You may do this assignment with a partner if you wish. Make sure both of you understand how to do all pieces of the code.

Level 1

(a) Reverse: Write a method that takes a string and returns a string that is its reverse. 

Plaintext: The message to encrypt
Ciphertext: tpyrcne ot egassem ehT 

public static String reverse (String plainText)

Level 2

(b) One Letter Caesar Shift: Write a method that takes a string (that is a single word!!) and shifts the letters one letter over. Convert all letters to small letters before you encrypt. Leave spaces alone. Note that z should be a!

Plaintext: baby
Ciphertext: cbcz

public static String caesar (String plainText)

Level 3

(c) Multi-letter Caesar Shift: Write a method that takes a string (that is a single word!!) and shifts the letters an arbitrary number of letters over. Convert all letters to small letters before you encrypt. Leave spaces alone. Note that more than z may need to wrap around.

Plaintext: baby    
Letters to shift: 14
Ciphertext: popn

public static String caesar2 (String plainText, int num)

(d) Pig Latin: Write a method that takes a string (that is a single word!!) and returns the Pig Latin of the word. To translate something to Pig Latin, take off the first letter and put it on the end of the word then put 'ay' on the end.

Plaintext: baby
Ciphertext: abybay

Plaintext: jump
Ciphertext: umpjay

public static String piglatin (String plainText)

Level 4 & Bonus

Do any one of the following for a level 4. Do more than that and they are bonus.

(e) Date Shift Cipher: Based on the Caesar cipher. To make the encryption harder to breaker, we vary the amount of shift from letter to letter. One way to do this is to use a date as the key for your message. Suppose that you are sending a message on March 29, 2003. The date can be written as 03-29-2003 or 03292003. Disregard the lending zero and you have: 3292003.

3292003
abba

So, shift the a by 3, the b by 2, the b by 9, the a by 2. You would repeat the date over again if the word was longer.

Plaintext: abba   
Date: Feb 29, 2003
Ciphertext: ddkc

Make up your own method declaration. The date can be passed as an int[], an int, or a String. Whatever you prefer! Get the date from the user (you might choose that they enter it in using numbers).

(f) Random mono-alphabet cipher: Unlike the Caesar cipher, as a key we don’t use numbers but words. Suppose the key word is FEATHER. Then we first remove duplicate letters, yielding FEATHR, and append the other letters of the alphabet in reverse order.

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

F

E

A

T

H

R

Z

Y

X

W

V

U

S

Q

P

O

N

M

L

K

J

I

G

D

C

B

Write a program that gets any key word from the user and a word to encrypt and then returns the encrypted word.

Plaintext: froggie
Key Word: feather
Ciphertext: rmpzzxh

public static String randomMonoAlpha(String plainText, String keyWord)

(g) Pair-Swap: This cipher divides the string into pairs. Each pair of letters is swapped.

Plaintext: Turing
Ciphertext: uTirgn

public static String pairSwap(String plainText)

(h) Alberti's code: This code provides two alphabets for the key. The algorithm chooses from alphabet 1 for the even numbered indices and alphabet 2 for the odd numbered indices. In the following example, a could be b (even postion) or it could be f (odd postion). This makes it harder to guess at the message using letter frequencies.

Plaintext: computer

Alpha 0: abcdefghijklmnopqrstuvwxyz
Alpha 1: bcdefghijklmnopqrstuvwzyza
Alpha 2: fghijklmnopqrstuvwxyzabcde

Ciphertext: dtnuvxfw 

public static String alberti(String plainText)

Rubric:

Knowledge (16) Level 4 Level 3 Level 2 Level 1
Methods (12) A Level 4 method completed in addition to Level 3. A Level 3 method completed in addition to Level 2. A Level 2 method completed in addition to Level 1. Level 1 method completed.

 

Communication (4) Level 4 Level 3 Level 2 Level 1
Comments (4) Pre/Post or @return /@param are extremely well done. Great comments. Pre/Post or java doc is very well done. Many good comments. Pre/Post or java doc are present. Some comments. Title comments at least. Pre/Post or java doc is extremely weak or missing. Very poor comments.