CCSU Spring, 1999 Project 4 Posting Date: February 2, 1999 Due Date: April 23, 1999 Relevant Demos: Demo 15 (ArrayDemo.java) and Demo 17 (MartianToEnglishApplet.java) This project comes in only 1 part. It covers the material covered in Chapter 6 on arrays. Background: Caesarean ciphers are a class of codes related to ones invented by the ancient Romans for transmitting battlefield messages. The original coding method involved wrapping a leather strip around a round stick and writing the message down the leather wrapped stick. But in modern terminology, a Caesarean code is a code which depends on shifting letters of the alphabet a fixed distance from their original position. The coding method can best be illustrated by an example. Suppose we have Key: 3 Plain Text Message: Attack the Gauls at dawn! First, ALL letters are changed to uppercase, and all blanks and punctuation marks are removed from the plain text message, giving us: Key: 3 Plain Text: ATTACK THE GAULS AT DAWN Next, two copies of the alphabet are constructed, with the second one shifted by the key length, which in this case is 3: ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ Then the overhang on the lower copy is wrapped around, giving us: ABCDEFGHIJKLMNOPQRSTUVWXYZ XYZABCDEFGHIJKLMNOPQRSTUVW Finally, the lower copy of the alphabet is used to put the message into code, giving us: Key: 3 Coded Text: XQQXZHQEBDXRIPXQAXTK To decode, just reverse the process: Key: 3 Plain Text: ATTACKTHEGAULSATDAWN Description: Write an Applet to put a message input by the user into code, using a Caesarian cipher. Your Applet Panel should contain a TextField where the user types in the message, and a second text field where the user types in the key. Your Panel should also contain two buttons, titled "Code" and "Decode". When the user clicks the Code Button, the encoded message should appear in a third TextField (rather than being drawn directly on the Applet Panel). On the other hand, when the user clicks the Decode button, the decoded message should appear in the TextField. Note that there are no responses to pressing the Enter key in this Applet. All actions are carried out as a result of pushing one of the two Buttons on the Applet Panel. Note also that the sender should be able type in the key as well as the message. The sender should be expected to have a properly prepared message, all in upper case with no blanks and no numbers. The key should be an integer between the values of -25 and 25. Note that the receiver could decode the message simply by using your program and the negative of the original key. Test to be sure this works. (If it does not, you made a mistake.) Hints: To convert a letter to a number from 0 to 25, try using num = (int) letter - (int) 'A'. To wrap the alphabet around, try using the mod operation, as in codeNum = (num + key) % 26. Because the % operation never works properly on negative numbers in any computer language, you first have to test to be sure num + key > 0. So the code looks something like codenum = num + key; if( codenum < 0 ) codenum = codenum + 26; codenum = codenum % 26; To convert a code number to a code letter, try using codeLetter = (char) (codeNum + (int) 'A');. Notes: (1) Your files MUST be named CodeApplet.java, and CodeApplet.html so I can easily find them. (2) Each of your programs must begin with a remark box as described in project 1. (3) Each method in your program must begin with a remark box as illustrated in the demos. Due: Friday, April 23, 1999 AT THE BEGINNING OF CLASS.