If the Offset Value Is 1 and the Original Text Message Is

If the Offset Value Is 1 and the Original Text Message Is

CSCI 1100/1202

Assignment 8

Due: 8:30 am, Friday, March 15th or 8:30am, first day of classes after Strike ends, whichever is later. The submit script will be working by Monday and can be used any time before the ultimate due date (~hawkey/1100/submit8).

For this assignment, you are to create a program (Cipher.java) that encodes and decodes text messages using a Caesar cipher (you can find details of how the cipher works at For the purpose of this assignment, the decoding of a Caesar cipher is a simple task - as the offset value is already known, no guessing is required.

If the offset value is 1 and the original text message is:

The lazy dog catches no fleas.

The encoded message should be:

UIF MBAZ EPH DBUDIFT OP GMFBT.

If the offset value remains at 1 and the encoded message is decoded, the original message (in all caps) should be output.

Note that the original message gets converted to all caps before it gets encoded and that only characters between A-Z get shifted - the rest of the message (spaces and punctuation) remain the same.

The offset value can be either positive or negative. If a value >= 26 (+ or -) is entered, the value should be constrained to be within the range 0..25 (+ or -).

This assignment does not require any arrays, but does rely on the similarity of a String to an array when encoding and decoding a message (think for loop). The menu structure is very similar to that used in Assignment 5. Use at least 4 methods when writing the program, so that the main method is mostly used for controlling the flow of work, instead of implementing all the functionality.

Here is a sample of the program running:

borg:~/1100$ java Cipher

*********************

* Cipher *

* *

* Kirstie Hawkey *

* *

* B00001149 *

*********************

****************************

* 1. Set cipher code. *

* 2. Encode text. *

* 3. Decode coded text. *

* 4. Exit the program *

****************************

Enter your choice: 2

Enter the text to encode: Hello World!

Encoded text is: HELLO WORLD!

****************************

* 1. Set cipher code. *

* 2. Encode text. *

* 3. Decode coded text. *

* 4. Exit the program *

****************************

Enter your choice: 1

Enter the offset value for a caesar cipher: 7

****************************

* 1. Set cipher code. *

* 2. Encode text. *

* 3. Decode coded text. *

* 4. Exit the program *

****************************

Enter your choice: 2

Enter the text to encode: My dog has fleas.

Encoded text is: TF KVN OHZ MSLHZ.

****************************

* 1. Set cipher code. *

* 2. Encode text. *

* 3. Decode coded text. *

* 4. Exit the program *

****************************

Enter your choice: 3

Enter the text to decode: tf kvn ohz mslhz

Decoded text is: MY DOG HAS FLEAS

****************************

* 1. Set cipher code. *

* 2. Encode text. *

* 3. Decode coded text. *

* 4. Exit the program *

****************************

Enter your choice: 1

Enter the offset value for a caesar cipher: 25

****************************

* 1. Set cipher code. *

* 2. Encode text. *

* 3. Decode coded text. *

* 4. Exit the program *

****************************

Enter your choice: 2

Enter the text to encode: abcde vwxyz)(

Encoded text is: ZABCD UVWXY)(

****************************

* 1. Set cipher code. *

* 2. Encode text. *

* 3. Decode coded text. *

* 4. Exit the program *

****************************

Enter your choice: 1

Enter the offset value for a caesar cipher: -2

****************************

* 1. Set cipher code. *

* 2. Encode text. *

* 3. Decode coded text. *

* 4. Exit the program *

****************************

Enter your choice: 2

Enter the text to encode: abc/xyz

Encoded text is: YZA/VWX

****************************

* 1. Set cipher code. *

* 2. Encode text. *

* 3. Decode coded text. *

* 4. Exit the program *

****************************

Enter your choice: 8

You must enter a number between 1 and 4 to indicate your selection.

Enter your choice: 4

Thank you for using Cipher for all your code breaking and code making needs.