CS200Assignment4 SentenceEncryption Solution

Assignment Instructions
Page 565-566 #77 in text
Assignment Explanation

For this assignment, you need to create an encryption program. The program must consist of an encryption class and a client program that creates an object of the class and uses it. The encryption must be random. The program must be able to encrypt a sentence entered by a user. Then, it must be able to decrypt the sentence.
Key Information

• There are two arrays of characters given in the example. One array holds the alphabet in its correct order. The second array holds the encrypted alphabet. These will be two parallel arrays. To encrypt a letter, the corresponding spot from the regular alphabet array will be replaced with the letter in the encrypted array. To decrypt, the program will do the opposite.
• The encryption must be random. So, the way the letters are placed in the encrypted array is what needs to be random. Each time the program runs it would be different.
• Since this program needs to bring in a sentence and only deals with letters, spaces and non-letter characters will have to be dealt with.

1. Create a user-defined class to handle the encryption
a. The class needs to have a constructor and all the necessary members and methods
b. Creating a toString() method is useful so you can see the encrypted alphabet after it is created
c. The constructor will create the randomized array of layers
2. Create a client class
a. The client class with have a main method to run the program
b. This is where the user will be asked to enter a sentence to encrypt and decrypt
i. The scanner class is used to get the input from the user
c. Must create an object of the encryption class

 User-defined classes: allows a programmer to create a definition that can be used to create objects of that class
o Pg 374-417 of the text is all about creating user-defined classes, including constructors and methods
o All the examples include a client class – the client class is what has a main method and actually runs the program; the user-defined class is just a definition that can be called when an object of that class is created in the client class
 toString() method: allows for outputting a text version of an object (useful for outputting the encrypted alphabet)
o Pg 404 – 410 of the text explains the toString() method
 Math.random() – built-in way of creating random numbers
o Pg 126-128 talks about the random method
o Math.random()
Arrays – variables that can hold more than one value in a list type format
o Pg 466-545 is all about arrays and how to work with them
o Parallel arrays are arrays who are the same length and have elements that designate to each other (regular alphabet and encrypted alphabet)

Powered by