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:

  1. 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.
  2. Has a static method encrypt which takes as argument a String plaintext and an int n, returning a String of ciphertext.
  3. 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

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!