Question: Cipher Program Specifications: You are to write a program called, Cipher123 that reads in an encoded message using the 1-2-3 cipher and returns the decoded

Cipher

Program Specifications: You are to write a program called, "Cipher123" that reads in an encoded message using the 1-2-3 cipher and returns the decoded message. The program should continue prompting for additional encoded messages until the user chooses to quit the program.

When decoding a message, we take the first letter of the first word, the second letter of the second word and the third letter of the third word and concatenate them. We repeat this same process 1-2-3 until there are no more words in the phrase. Suppose we received the message "Randy's lucky penny" that we know is encrypted using 1-2-3 encryption. We would take the first character from the first word ( 'R' ) and concatenate it with the second character of the second word ( 'u' ) and concatenate that with the third character of the third word ( 'n' ). Put it all together and we know that someone is telling us to Run.

Program Decomposition:

  1. public static String getUserInput(Scanner scnr) This method accepts a scanner parameter, prompts the user for the encoded message and returns the encoded message to the user. The user may enter the message on multiple lines and signals that they have finished entering the message by hitting the enter key on a line by itself. Data validation: The user must not enter an empty string as the decoded message. See sample run above.
  2. public static String decodeMessage(Scanner wordScanner) This method accepts a scanner parameter that is pointing to the encoded message. The method processes the string word by word using the 123 Cipher method and returns the deciphered string for printing. If while decoding, you come across a word that is smaller than the character needed (e.g., you need character 3 and the word is "go", you should print an appropriate message and stop decoding.
  3. Add more methods as needed

Sample Run

Enter the encoded message on one or several lines. Enter an empty line when you are finished typing your message:

Randy's lucky penny

<-- user hits carriage return to signal message is complete

You entered: Randy's lucky penny

The decoded message is: Run

Again? (Y/N)? y

Enter the encoded message on one or several lines. Enter an empty line when you are finished typing your message:

Randy's

lucky

penny

<-- user hits carriage return to signal message is complete

You entered: Randy's

lucky

penny

The decoded message is: Run

Again? (Y/N)? y

Enter the encoded message on one or several lines. Enter an empty line when you are finished typing your message:

<-- user hits carriage return for the message which is an invalid message

Please enter a message.

Funny Al's aly

<-- user hits carriage return to signal message is complete

You entered: Funny Al's aly

The decoded message is: Fly

Again? (Y/N)? n

If user enters a bad message (here the second word needs to have two letters - end the program and display Sorry - this message cannot be decoded using 123 Cipher. Again? (Y/N)?"

Enter the encoded message on one or several lines. Enter an empty line when you are finished typing your message:

What a crazy message

<-- user hits carriage return to signal message is complete

You entered: What a crazy message

Sorry - this message cannot be decoded using 123 Cipher.

Again? (Y/N)? n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!