6(a)String HandlingHard8 marks
A program is being developed to encrypt a message. The following terms are used in the encryption technique to be used:
| term | definition |
|---|---|
| plain text | The original message before it is encrypted. |
| cipher text | The encrypted version of the plain text. |
The encryption method to be used is based on the algorithm for the Caesar Box Cipher. All plain text messages to be encrypted must be 25 characters in length or less. If a message is less than 25 characters in length, then spaces are added to the end to make the padded plain text the required length.
A square grid of five columns and five rows is used. The padded plain text message is put into the grid row by row. The cipher text is obtained by reading the grid column by column.
For example, for the plain text This is a message (17 characters, including spaces), the padded plain text (using ∆ to show a space) is This∆is∆a∆message∆∆∆∆∆∆∆∆. The grid filled, row by row, with the padded plain text:
| T | h | i | s | ∆ |
|---|---|---|---|---|
| i | s | ∆ | a | ∆ |
| m | e | s | s | a |
| g | e | ∆ | ∆ | ∆ |
| ∆ | ∆ | ∆ | ∆ | ∆ |
The cipher text is obtained by reading the grid column by column: Timg∆hsee∆i∆s∆∆sas∆∆∆∆a∆∆
The programmer has defined the first program module as:
| module | description |
|---|---|
| AddPadding() | user prompt for and input of plain text • check plain text contains between 1 and 25 characters inclusive • re-input of plain text until it contains between 1 and 25 characters • if required, additional space characters are added to the end of the plain text to ensure it contains exactly 25 characters • return of amended plain text |
Write pseudocode for module AddPadding().
AddPadding() function
0 words