Homework 6 CMP12a Winter 2002 (Ira Pohl and Scott Brandt)

Due 2/25/2002, before midnight.

Cryptography HW6

This problem is to be graded and done alone.
-Ira Pohl and Scott Brandt

This is a modification and an elaboration of homework 5. Read this carefully as there are several places where
you must change your work from homework 5. This will give you additional understanding of character processing.

We will use both arrays and methods to develop an encryption scheme for character messages. We will read in messages using the tio function readChar(). This reads a character at a time from the console and returns its integer value. We will read a message up to the guard character #. This message will be no more than 255 character long. This is how long our array will be to store both the clear text and to produce encrypted test. We will read a series of messages until we hit the end-of-file value -1. This version of our program must be able to handle multiple-encryptions and decryptions.

public static void encrypt(char[] clearText, char[] codeText, int seed)

//takes clear text and produces encrypted text

This version of encryption should take the characters whose value is between 32 and 127 and encrypt them back to values 32 through 127. You should again devise a scheme that utilizes the seeded random number generator. This scheme needs to be invertable to someone knowing the seed and the random number generator in use. (Of course we know this is just the standard java method.) Test messages will contain any of the printable characters including digits, operators and tokens.

public static void decrypt(char[] codeText, char[] clearText, int seed)

//takes code text and produces clear text

You must develop the inverse formula to be followed in decryption and pass an appropriate random character value that will be used by decode().

You should write and test a decode() and encode() pair of methods that work appropriately.

Hand simulate these techniques to make sure you understand how this all works. If it works on one character than using proper array idioms it should work on the entire message.

The program should alternately encrypt and decrypt each message passed in by terminal io or redirected from a file until the end-of-file value terminates it.

use submit cmps012a-ip.w02 hw6 filename.java (Ira Pohl's class)
 or  submit cmps012a-sb.w02 hw6 filename.java (Scott Brandt's class)