Suppose, you are a Army person who is spying on enemy-country. You are on a secret mission to retrieve the top secrets of the enemy. You have succeeded in getting their top secrets. Now what you have to do - you have to send their secrets to your Army headquaters but you can't send the message directly you have to encrypt it, so that no other person can read it.
Enrypted Form: eYLA NwaC EITK MLT
The way to do it is that the number of rows and the number of columns in the figure (formed from the alphabets of the Message) lie between floor (sqrt(len(message))) and ceil (sqrt(len(message))). It also states that the number of rows is less than or equal to the number of columns, and that the area of rectangle thus formed is minimum. Based on the this criteria, we have to choose a set of values for rows and columns.
For the string haveaniceday, we have floor(sqrt(len(message))) = 3 and ceil(sqrt(len(message))) = 4.
3 * 3 = 9 < len(message) = 15
3 * 4 = 12 = len(message)
4 * 3 = 12 = len(message)
4 * 4 = 16 > len(message)
Out of the 4 possible squares, we can see that #rows = 3 and #columns = 4 is the best fit.
On building the figure, we get
So, ans : eYLA NwaC EITK MLT
The first line of input contains an integer denoting the no of test cases. Then T test cases follow. Each test case contains a string s.
For each test case in a new line print the encrypted text.
1<=length of string<=1000
eYLA NwaC EITK MLT
Sti ahn vee eMs
Geeyg ErRTh tyeot Eoaf vndi
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.