Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with the KEYWORD CIPHER ONLY (part B at the end) (I only added the other classes incase you needed a reference)! Also please
Please help with the KEYWORD CIPHER ONLY (part B at the end) (I only added the other classes incase you needed a reference)! Also please use JAVA
1. Make an abstract class* called Message. A Message object should have a String field called text and a flag called is Encrypted. A parameterized constructor - a String parameter only for the text. A new Encryption object is not encrypted. getText() isEncrypted() encrypt() - this is an abstract method. When implemented, it will replace the text with encrypted text and update the isEncrypted flag. Precondition: the text is not encrypted. decrypt() - this is an abstract method. When implemented, it will replace encrypted text with decrypted text and update the isEncrypted flag. Precondition: the text is encrypted. In this project, instance variables will need to be mutated. Ordinarily, you would make setText method, but that would defeat the purpose of the encryption. Instead, we will change the protection on the field text to protected instead of public so that the subclasses can mutate them. Do the same for isEncrypted. Note: your textbook recommends keeping private instance variables in Message but coding method setText and change Encryption Status as protected instead of public. 2. You will be asked to do one of the following initial encryption methods. a. Make a subclass of Message called Reverse. This subclass implements the two abstract methods by reversing the text. For example: hello there is encrypted as ereht olleh and: winter is encrypted as retniw b. Make a subclass of Message called Alternate. This subclass implements the two abstract methods by alternating the pairs of consecutive letters in the text. If the length of the text is odd, the last letter is not moved. For example: hello there is encrypted as ehll ohtree and: winter is encrypted as iwtnre C. Make a subclass of Message called SemiReverse. This subclass implements the two abstract methods by alternately swapping letters. So the first and last letter swap, the second and second-last are unchanged, the third and third-last swap, the fourth and fourth- last are unchanged, etc. For example: hello there is encrypted as eeelt ohlrh and: winter is encrypted as eitnew 3. Make a subclass of Message called CaesarShift. This subclass implements the two abstract messages with a Caesar shift cipher. A Caesar shift cipher is a substitution cipher in which each letter in the message is replaced with a letter n places further on in the alphabet. For example: In a Caeser shift cipher with n = 3, DAY would be replaced with GDB. In a Caeser shift cipher with n = 25, IBM would be replaced with HAL. Capital letters remain capitalized and lower-case letters remain lower-case. Punctuation and other characters are not encrypted. In addition to implementing the abstract methods, include two parameterized constructors. CeasarShift (String text): The default shift value is n = 3. CaesarShift (String text, int n): the client provides a value for n. Precondition: 1sns 25. B. KeywordCipher - This cipher does two things: a. The Keyword Substitution Cipher takes a keyword to initialize the encryption. The algorithm for the keyword cipher is as follows: put each letter of the keyword into the code, omitting duplicates. At the letter on which you end up, put the rest of the alphabet, again omitting letters which have already been used. Example 1: If the keyword was "trigonometric then encryption would be: a b c d e f g h i j k l m n o p q | t u v w x y z trigon mec d f n ik ipas u v w x y z a b You can use this table to encryptHi there" as "Ec veoso." Example 2: The keyword was pineapple tart would lead to the encryption table: a b c d e f g h i j k l m n o p q r s t u v w x y z pine aitr su v w x y z b c dfghjkmoq Write the code so that the constructor requires both a message and a String keyword (in that order). The numeric value should not be the empty string. You should encrypt only letters of the alphabet - do not encrypt (or decrypt) spaces, numbers, punctuation, etc. Convert the characters to all-capitals as the text will be given to you in a combination of capital and lower case letters
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