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 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
, b
, 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 number, using lowercase letters (a
, b
, etc.). For example, if there are words, then these letters are af
, which converts to . If there are words, then the letters are bc
, which converts to , the base- equivalent of the decimal number . 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 :
Message: | put the lime in the coconut |
---|---|
Step : | agddecdh put the lime in the coconut |
Step : | bbvspljgzkqxextiaokcpwpljvtfsy |
The input will contain test cases. Each test case will consist of two lines. The first line contains an integer and the second contains an encrypted or unencrypted message. Each message contains between and words, each from to 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 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 .
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
why does the output have spaces in it?