Encrypt Text by Columnar Transposition
Problem statement
For this exercise, use the following columnar transposition rule. Write the characters of text from left to right into rows with columns positions each. The last row may be incomplete. Read the occupied cells column by column, from the leftmost column to the rightmost, and within each column from top to bottom. Return the resulting ciphertext.
For this exercise, assume no padding is added. Preserve every input character, including spaces, punctuation, digits and letter case. Skip unoccupied cells and return an empty string for empty text.
Function
encryptTransposition(text: String, columns: int) → StringExamples
Example 1
text = "WEAREDISCOVERED"columns = 4return = "WECREDOEAIVDRSE"The columns contain WECR, EDOE, AIVD and RSE, read in that order.
Example 2
text = "abcde"columns = 3return = "adbec"Rows are abc and de. Read ad, be and c without adding padding.
Constraints
- For this exercise, assume
0 <= text.length <= 500and1 <= columns <= 500. - For this exercise, assume every input character is printable ASCII, from character code 32 through 126.