Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

Who holds the power in recruitment and selection?

Answered: 1 week ago