Question: Write a Java program that will encode plain text into cipher text and decode cipher text into plain text. Create a project and class
Write a Java program that will encode plain text into cipher text and decode cipher text into plain text. Create a project and class named HW7FirstnameLastname in NetBeans using your actual first and last names to hold your program. Create following methods and add them to your class: a method named encode (String p, int key) that takes a plain text p and encodes it to a cipher text by adding the key value to each alphabet character of plain text p using the ASCII chart. The method should return the encoded String. For example, if p = "attack at dawn" and key is 5, it should be encrypted as "fyyfhpefyeifas" because 'a'+5= 'f', 't'+5 = 'y', 'c'+5= 'h', 'k'+5 = 'p', +5= 'e', 'd'+5= '1', 'w+5= 'a', and 'n'+5 a method named decode (String c, int key) that takes a cipher text c and decodes it to a plain text by subtracting the key value from each alphabet character of c. The method should return the encoded String. Assume that the only characters allowed in Strings p and care lower-case alphabet letters and spaces. You don't have to validate input for correct characters, but you should make sure you only pass Strings with all lowercase letters for p and c to your methods. Provide the following menu using a do...while loop in the main method to the user. Options 1 and 2 in the menu should print the returned encoded or decoded text for the user. 1. Convert plain text to encoded cipher text 2. Convert cipher text to decoded plain text 3. Exit
Step by Step Solution
3.35 Rating (161 Votes )
There are 3 Steps involved in it
Java program that can encode plain text into cipher text and decode cipher text back into plain text Heres the code Java public class HW7FirstnameLastname public static String encodeString p int key S... View full answer
Get step-by-step solutions from verified subject matter experts
