Write a program that implements HILL Cipher encryption and decryption algorithms.
You can assume that the size of the MATRIX KEY is 2X2. The program should be able to
perform either encryption or
decryption. The program must
take two inputs. The first input must be either 1 or 2, with 1 signaling
encryption and 2 signaling decryption. The second input depends on the first
input. In case of encryption, the second input consists of MATRIX KEY, and
plaintext - a sequence of LOWER CASE letters.
In case of decryption, the second
input consists of MATRIX KEY, and ciphertext a sequence of UPPER CASE
letters. Your program should output encrypted or
decrypted message accordingly with appropriate descriptive message.
Pay attention: in case of decryption your program
must to calculate the INVERSE MATRIX. The program must output the
INVERSE MATRIX along with plaintext
in case of decryption.
Also, your program must to check validity of the key.
In case of invalid keys you can decide to exit from
the program or to ask user to re-enter the key.
You can decide on number of attempts. All choices should be well documented in
comments and in output messages.
Bonus 1 (10 points): Write the above program for the 3X3 Matrix
Key. For mathematical formulas see HERE.
Pay attention that you would need to perform all calculations MOD 26
and to find multiplicative inverse of DET(A) mod 26
Bonus 2 (10 points): Combine Affine and Hill Cipher programs to be able to perform 2-step encryption and decryption.