![]() |
VOOZH | about |
Given a string S, the task is to encrypt the string and decrypt the string again to the original form.
Encryption Technique: If L is the length of the string, then take two values, one the ceil of ?L (say b), and the other floor of ?L (say a), and make a two-dimensional matrix having rows = a, and columns = b.
If rows*columns < L, then increase the value of a or b, whichever is minimum. Fill the matrix with the characters of the original string sequentially. After obtaining the matrix, read the matrix column-wise and print the obtained string.
Decryption Technique: If L is the length of the encrypted string, then again find the two values a and b, where a is the ceil value of the ?L and b is the floor value of the ?L. Similarly create a 2D Matrix in which store the string column-wise and read the matrix row-wise to get the string in the original form.
Encryption Approach:
Decryption Approach:
Below is the implementation of the above approach:
Gsree keFGskoe Geeks For Geeks
Time Complexity: O(?n * ?n) ? O(n)
Auxiliary Space: O(n), where n is the length of the given string.