Question: JAVA program Caesar Cipher Please complete decryption section (match encryption section). Use comments. At the bottom you'll find the uncompleted java code Choose between encryption
JAVA program Caesar Cipher
Please complete decryption section (match encryption section). Use comments. At the bottom you'll find the uncompleted java code
Choose between encryption and decryption (if-else statement). Type in either plaintext or ciphertext and print out the result after encryption or decryption (Scanner class). Your java program (loop) should also allow the user to repeatedly input more than one ciphertexts or plaintexts to be decrypted or encrypted (loop).
Please follow exact format for your print out.
----jGRASP exec: java CaesarCipher
Please indicate what you want to do: 1- encryption 2- decryption
1
Please enter your plainText to be encrypted:
History is punctuated with codes.
The ciphertext (caesar cipher with offset of 3) is:
Klvwru|#lv#sxqfwxdwhg#zlwk#frghv1
Encryption/Decryption again: y/n
y
Please indicate what you want to do: 1- encryption 2- decryption
2
Please type in the ciphertext to be decrypted:
Klvwru|#lv#sxqfwxdwhg#zlwk#frghv1
ciphertext is: Klvwru|#lv#sxqfwxdwhg#zlwk#frghv1
Plaintext(caesar cipher with offset of 3) is: History is punctuated with codes.
Encryption/Decryption again: y/n
n
----jGRASP: operation complete.
public class Project2 { public static void main(String[] args) { Scanner stringscan = new Scanner(System.in); //string scanner to be utilized Scanner intscan = new Scanner(System.in); //integer scanner to be utilized final int MOVE_DOWN = 3; //constant offset for caesar cipher String plainText = ""; //plaintext String variable String cipherText = ""; //ciphertext String variable int choice; //integer variable for user's choice, which is 1 or 2 String again = ""; //String variable for user to determine if they want to continue (y/n) do { System.out.println(" Please indicate what you want to do: 1- encryption 2- decryption"); //user menu choice=intscan.nextInt(); //store the user input into the choice variable if (choice == 1) //user chose to encrypt { System.out.println("Please enter your plainText to be encrypted:"); //user asked to enter plaintext message plainText= stringscan.nextLine(); //store the message in plainText variable System.out.println("The ciphertext (caesar cipher with offset of "+ MOVE_DOWN +") is:"); //output the encrypted message for (int i=0; i < plainText.length(); i++) //loop thru each character { char position = plainText.charAt(i); //identify character position int count = (int) position + MOVE_DOWN; //convert the char to an integer and add the offset position = (char) count; //convert the integer back to a char cipherText = Character.toString(position); //convert the char to a string System.out.print(cipherText); //print the cipherText } //prompt the user for another round of encryption/decryption - Scanner System.out.println(); System.out.println(" Encryption/Decryption again: y/n"); again=stringscan.nextLine(); } else if (choice == 2) //user chose to decrypt { } }while(again.equals("y")); //when user enters 'n', the loop exits the program }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
