Question: I need help writing a program for homework. I started it but it is a lot harder than I thought it would be. It must
I need help writing a program for homework. I started it but it is a lot harder than I thought it would be. It must do the following:
- The program will prompt the user for a single sentence.
- The program will then scan for the entire sentence and store it in a valid String object.
- Assume this sentence can contain any of the letters. This includes both uppercase and lowercase variants.
- Also assume that it can contain a space, any of the 10 digits and the following punctuation: a comma, a period, an exclamation point and a question mark.
- Any other character would be considered invalid and should be ignored by your program. However, it should not crash your program.
- Determine the length of the String and make a single dimensional character array (not a String array) big enough to hold every character from the String. You will probably want to consider using the String length method to help with this. Use a loop of your choosing to assign the values to the array.
- Prompt the user for a number between 1 and 5. The prompt should specify that this is for encrypting the message. Validate the value before moving on. If the user typed something outside the range, continue to prompt them until they type in a valid number.
-
- After collecting the number from the user, use a Caesar shift cipher to shift every letter in the array forward by the number collected from the user in the previous step. For instance, if the user typed in the number 2, then the Caesar shift would shift every character forward 2 characters. The letter B would become a D. Remember that uppercase and lowercase letters are different values.
- All the calculations and assignments to the 2nd array will take place in a method called shiftCipher. This method should be placed in the same file (Csci1302_hw1.java)
- Use whichever programming technique for determining the shift decision process. For example, you could use a multi-level if, or a switch statement, or another technique. Be aware that every character is represented by a numerical value. You can use this fact to your advantage.
- Create a 2nd character array and store the results of the Caesar cipher in the array. This array should be the same length as the first array. For example, assume that the user typed the word Car as the first word in their sentence and then they submitted the number 3 for the shift. What is stored in the array at location [0] in the first array is the letter C, now I will store the letter F at the [0] location in the 2nd array. The letter a would be stored at location [1] in the first array and now location [1] in the 2nd array will store the letter d.
- Make sure your program handles character shifts past the end of the alphabet. For example, what if you need to shift the letter z forward 4 characters to the character ~. Use an ASCII table to determine the correct character assignments.
-
- After encrypting the message and storing it in the 2nd array, use a Substitution cipher to further encrypt the sentence that resulted from the Caesar shift. If you arent aware of how a substitution cipher works, there is plenty information on the web. The Ciphertext key that you use is up to you but make it interesting. For example, dont just shift the letters like the previous step, change a b to something like a &. For your key, you can reuse letters and any valid symbols you want, but make sure you handle any character that resulted from the Caesar shift in the previous step. As you may have already figured out, you will be storing this 2nd level encrypted message in 3rd array of characters.
- All the calculations and assignments to the 3rd array will take place in a method called substCipher. This method should be placed in the same file (Csci1302_hw1.java)
- You must use a single multi-level if statement (an if with a lot of if else) for the decision making process for this level of encryption.
-
- Using a for loop for each array, traverse each array and print out each message on its own line. Line 1, will contain the original message. Line 2, will contain the shifted message and Line 3 will contain the substitution message. This must be done after the first six steps have been completed. This should be placed in the main method of the program. There should be labels describing what each line contains. For instance: Original Message: .
In java please.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
