Requirement
5. Write a program which can encode and decode text messages according to the following rules:
1. Put the message in a square NxN matrix, where N is an odd integer number
2. If the matrix is not completely filled with the message characters, put signs in empty cells
3. Display the matrix contents following the spiral path starting from the central element as shown in
Fig. 1
Fig. 1. Matrix reading order
The message to encode or decode is placed in a text file, which is provided by the user. The encoded
or decoded message is appended by the program to the same file. The operating mode (encoding or
decoding) is selected by the user.
Example: “Follow the red line!”
The message contains 20 characters, so the smallest odd-order matrix which can accommodate the
message is 5x5:
Following the pattern shown in Fig. 2, the encoded message is: “edenir the !**l wFollo”
To decode the massage, it has to be placed in the matrix following the spiral pattern and then read
row by row.