String Encryption
InterviewTime limit1sMemory limit128 MB
Clean the plaintext (drop spaces, uppercase), then invert the given transposition decryption rule to produce the matching ciphertext.
- Level
Medium5 of 10
- Topics
- String, Implementation, Simulation, Math
- Solved
- No attempts yet
Problem
To keep others from reading their messages freely, many people use encryption algorithms to turn a plaintext (message) into a ciphertext. A transposition cipher does not change the characters themselves; it only rearranges the order in which they appear, and it must be possible to turn the ciphertext back into the plaintext later.
The decryption rule (ciphertext → plaintext) used in this problem is as follows. Read the first character of the ciphertext, then read the character positions away (skipping the characters in between). Keep repeating this; once you move past the end of the string, go back to the second character and repeat the same process. Continuing this way until every character of the ciphertext has been read exactly once yields the plaintext.
Your task is the reverse process: encryption. First remove every space between words from the plaintext and convert every letter to uppercase. Then output the ciphertext that, when the decryption process above is applied to it, reproduces exactly that cleaned string.
Input
The input consists of several test cases.
Each test case is given on two lines. The first line contains an integer (), and the second line contains the plaintext.
The plaintext is between 1 and 10,000 characters long and consists only of uppercase and lowercase letters and spaces.
When is given on the first line, the input ends and that test case is not processed.
Output
For each test case, print the ciphertext produced by the method described above, one per line. The ciphertext is the string obtained from the plaintext by removing spaces, converting every letter to uppercase, and rearranging the order of the characters.