Question: (JAVA) A Caesar cipher is one of the simplest encryption methods. It is a substitution method in which each letter in the text is replaced
(JAVA)
A Caesar cipher is one of the simplest encryption methods. It is a substitution method in which each letter in the text is replaced by a letter a fixed number of positions down in the alphabet. If the shift takes you past the letter z then it wraps back to the letter a. The easiest way to handle the wrap is to perform modulo arithmetic and use the remainder after division by 26 as the position in the alphabet (remainder = newIndex % 26)
-
Import the scanner and math classes
-
Create the public class CaesarCipher
-
Create the public function main()
-
Create a variable declaration section based on the scope of your class described below
-
Construct a scanner on System.in
-
Your class must do the following including comment lines and appropriate indenting:
-
Prompt the user to input a string that can contain letters, digits and special characters.
-
Prompt the user to input an integer cipher shift between 1 and 4. Loop until the cipher shift satisfies these constraints
-
Modify the string by using the Caesar cipher encryption algorithm, replacing every letter with the letter that is cipher shift units to the right.
Hint: You will need a loop to accomplish c) and d). It may be easier to convert the string to lowercase before you enter the loop (saves having to cipher uppercase characters).
- Once encrypted capitalize every vowel and convert consonants to lowercase. Leave the digits and other characters alone.
- Output the following:
- The original string was: aBcdEf12$rs and your cipher shift was 2
- The encrypted string is: cdEfgh12$tU
-
Help would be greatly appreciated as I am struggling to create this program!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
