ECOO '16 R2 P2 - CC+

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 2.5s
Memory limit: 64M

Problem type

CC+ is a cyclical cypher. A cyclical cypher is a method of encrypting messages in which every letter in a message is "rotated" some number of positions. For example, if the letters are rotated 1 position then a becomes b, b becomes c, and so on (z becomes a).

In a CC+ encryption (Cyclical Cypher Plus) the number of positions a given letter is rotated is based on an integer key value plus the sum of the letters to the right (where a = 0, b = 1, etc.). Messages to be encrypted by CC+ must only contain lowercase letters and space characters. No uppercase, digits, punctuation or other types of characters are allowed. Spaces in the original message are removed in the encrypted version.

Before the letters get rotated, special encoding characters are added to the left of the message string. The first two characters represent the number of words in the message as a base 26 number, using lowercase letters (a = 0, b = 1, etc.). For example, if there are 5 words, then these letters are af, which converts to 05. If there are 28 words, then the letters are bc, which converts to 12, the base-26 equivalent of the decimal number 28. This is followed by a string of characters, each of which represents the length of one of the words in the message (in the order they appeared).

Here's an example encoding using key 5:

Message:
put the lime in the coconut
Step 1:
agddecdh put the lime in the coconut
Step 2:
bbvspljgzkqxextiaokcpwpljvtfsy

The input will contain 10 test cases. Each test case will consist of two lines. The first line contains an integer K (1 \le K \le 2 \times 10^9) and the second contains an encrypted or unencrypted message. Each message contains between 2 and 675 words, each from 1 to 25 characters in length. Words in unencrypted messages are separated by a single space character. Your program should either encode or decode each message (as appropriate) using key K and output the result on a single line.

Note that the sample input below consists of only two test cases, but the data files will contain 10.

Sample Input

5
put the lime in the coconut
13
ccxupnkiivspyqdtlsshwc

Sample Output

bbvspljgzkqxextiaokcpwpljvtfsy
and drink it all up

Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org


Comments


  • 4
    marshmelllo  commented on Feb. 27, 2017, 3:12 p.m. edited

    why does the output have spaces in it?