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”.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here