Create an interface “MessageEncoder’ that has a single abstract method “encode (plain Text)”, where plaintext is the message to be encoded. The method will return the encoded message. Create a class...


Create an interface “MessageEncoder’ that has a single abstract method “encode (plain Text)”, where plaintext is the message to be encoded. The method will return the encoded message. Create a class “ShuffleCipher” that implements the interface “MessageEncoder”. The constructor should have one parameter called n. Define the method “encode ()” so that n swaps are made on the message string, a swap is done on two characters of the string at a time, starting from the corner two elements.


For example, if the message is abcdefghi. Suppose we have to do n=2 swaps.


In the First swap, the characters ‘a’ & ‘i’ are swapped. The message after first swap is “ibcdefgha”.


In the Second swap, the characters ‘b’ & ‘h’ are swapped. The message after second swap is “ihcdefgba”.


The final answer is “ihcdefgba”.

Nov 22, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here