Question
Create a program ShiftCipher (hand in ShiftCipher.java) which accomplishes the following: Has a static method shiftAlphabet taking an integer argument n returning the alphabet as
Create a program ShiftCipher (hand in ShiftCipher.java) which accomplishes the following:
- Has a static method shiftAlphabet taking an integer argument n returning the alphabet as an array of chars shifted by n. Note that calling this method with n == 0 should return the regular, unshifted, alphabet.
- Has a static method encrypt which takes as argument a String plaintext and an int n, returning a String of ciphertext.
- Has a static method decrypt which takes as argument a String ciphertext and an int n, returning a String of plaintext. Note that decrypting with a value of n should be equivalent to encrypting with a value of -n (negative n). That might give you a very easy way to program the decrypt method.
Sample Code:
public static void main(String[] args) {
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/*for (char letter: alphabet.toCharArray()) {
System.out.println(letter);
}*/
char alphabetArray[] = alphabet.toCharArray();
//System.out.println(alphabetArray[(0 - 11 + 26) % 26]);
//System.out.println(alphabet.charAt((0 - 11 + 26) % 26));
System.out.println(alphabet.indexOf("L"));
Test your programming by encrypting a message and verifying you recover the original message upon decryption. Prompt the user to enter a plaintext message and an integral shift value. Your program should convert the message to uppercase and output the ciphertext. Sample output is below:
Please enter a plain text message for encryption: informatics Please enter the shift value (key) for the cipher: 3 The ciphertext is: LQIRUPDWLFV To verify, the decrypted encrypted text is below: INFORMATICS
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started