1.Create an interface MessageEncoder that has a single abstract method encode(plainText), where plainText is the message to be encoded. The method will return the encoded message.

2.Create Abstract class EncoderDecoder that has no methods.

3.Create a class SubstitutionCipher that extends class EncoderDecoder and implements the interface MessageEncoder, as described in parts a and b. The constructor should have one parameter called shift. Define the method encode so that each letter is shifted by the value in shift. For example, if shift is 3, a will be replaced by d, b will be replaced by e, c will be replaced by f, and so on. You may wish to define a private method that shifts a single character.

4.Create a class ShuffleCipher that extends class EncoderDecoder and implements the interface MessageEncoder, as described in parts a and b. The constructor should have one parameter called n. Define the method encode so that the message is shuffled n times. To perform one shuffle, split the message in half and then take characters from each half alternately. For example, if the message is "abcdefghi", the halves are abcde and fghi. The shuffled message is afbgchdie. You may wish to define a private method that performs one shuffle.

5.Create an interface MessageDecoder that has a single abstract method decode( cipherText), where cipherText is the message to be decoded. The method will return the decoded message.

6.Modify the classes SubstitutionCipher and ShuffleCipher, as described in parts c and d, so that they implement MessageDecoder as well as the interface MessageEncoder.

7.Finally, write a menu driven program that allows a user to encode and decode messages entered on the keyboard.

Sample Output

Welcome to the Cipher program Type 1 for Substitution Cipher. Type 2 for Shuffle Cipher.
1
What is the key (shift amount) for your code? 3
Enter a message to be encoded or decoded. ABC DEF
Encode (E) or Decode (D)
E
Encodes to: DEF#GHI
Do you want to do another message (Y) Y
Welcome to the Cipher program Type 1 for Substitution Cipher. Type 2 for Shuffle Cipher.
1
What is the key (shift amount) for your code? 3
Enter a message to be encoded or decoded. DEF#GHI
Encode (E) or Decode (D)
D
Encodes to: ABC DEF
Do you want to do another message (Y) Y
Welcome to the Cipher program Type 1 for Substitution Cipher. Type 2 for Shuffle Cipher.
2
What is the key (shuffle amount) for your code? 2
Enter a message to be encoded or decoded. ABC123
Encode (E) or Decode (D)
E
Encodes to: A21CB3
Do you want to do another message (Y) Y
Welcome to the Cipher program Type 1 for Substitution Cipher. Type 2 for Shuffle Cipher.
2
What is the key (shuffle amount) for your code? 2
Enter a message to be encoded or decoded. A21CB3
Encode (E) or Decode (D)
D
Decodes to: ABC123
Do you want to do another message (Y) N
Process finished with exit code 0
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.