I need to write a program to encrypt and decrypt a given plain text. The input will be a string without spaces. The program should read and store the string as a square matrix, with each element in the matrix being one character. Hence the number of characters in the input string can only be perfect squares. If they are not, the program should throw an error.
Encryption technique:
Input: abcdefghi
a b c
d e f
g h i
Exchanging rows will result in the following
g h i
d e f
a b c
The encrypted text then is ghidefabc
Therefore, For a matrix with 3 rows, swap rows 1 and 2. For a matrix with 4 rows, swap rows 1 and 4, swap rows 2 and 3. For a matrix with 5 rows, swap rows 1 and 5, swap rows 2 and 4 and so on. The program should print the input string which is plain text. Print the encrypted text. And then print the decrypted text. [Hint: Reverse of encryption is decryption and you may use just one method for both the processes. Such a cipher is called symmetric cipher]
Sample output:
Plain Text: welcometosanjose
Encrypted text: joseosanometwelc
Decrypted text: welcometosanjose