In: Computer Science
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Thank You !! =========================================================================== import java.util.Scanner; public class ShiftCipher { public static void main(String[] args) { String plaintext = "Feistel cipher structure uses the same algorithm for both encryption and decryption"; Scanner scanner = new Scanner(System.in); //1. User must enter the value of key from command prompt and print it at command prompt. System.out.print("Enter key : "); int key = scanner.nextInt(); //2. Print the cipher text and the plaintext at the command prompt after encryption and decryption. String encrypted = shift(plaintext, key); System.out.println("Encrypted text: " + encrypted); System.out.println("Decrypting..."); System.out.println("Decrypted text: " + shift(encrypted, -key)); //3. Test your algorithm for 5 different key values and please give screenshots of command prompt input and outputs. // Repeat 5 times for 5 diffent keys } public static String shift(String text, int key) { StringBuilder modified = new StringBuilder(); for (char letter : text.toCharArray()) { char converted = (char) (letter + key); modified.append(converted); } return modified.toString(); } }
==========================================================================