Barrel cypher
Description
Discuss (16 comments)The goal of this puzzle is to write a barrel cypher decoder with the smallest code size possible.
The cypher works with a key and a message. The key is a suite of numbers between 1 and 9, the message a space separated list of lower case words. To encrypt a message, we repeatedly travel through the numbers of the key from left to right and then from right to left and shift the letter in the alphabet by the corresponding number.
Example
- key 1595
- message hello world
We start processing the words and using the digits from the key from left to right:
h+1=i, e+5=j, l+9=u, l+5=q
Now that we used all the digits, we do it again from right to left:
o+5=t, the space is discarded, w+9=f, o+5=t, r+1=s
And finally we repeat the process, starting from left to right:
l+1=m, d+5=i
The encrypted message is: ijuqt ftsmi
Input Specifications
Your program must take a single command line argument: the name of a file.
The input file is structured as follows:
- the first line contains the number n of test cases
- each test case is composed of 2 lines
- the first line of the test case is a number ki the cypher key
- the second line of the test case is a message (all lower case space separated words)
Example:
2
123
xgofqnf vr fqeftfkcsuu
9972
fqltg waxpahoolab dwpvg
Output Specifications
The output result should printed on the standard output. For each encrypted message of the input file you must produced the corresponding decrypted message.
For the previous example, the expected output is:
welcome to codercharts
where programmers unite
Scoring
The scoring is based on the code size of your program, the smaller the code, the higher your score. The first 30 spaces, tabs and newlines are ignored, each additional one counts as one character.
| Type | Puzzle | Pass | 1400 | Fail | 368 | ||
| Scoring | Language | Level | Easy | Points | 100 | ||
| Tags | cryptography | ||||||
Unit Tests
| Name | CPU Unit | Memory Unit |
|---|---|---|
Twittering100 tests, longest message is 29 chars |
||
Cryptic mail50 tests, longest message is 175 chars |
||
Spy versus spy20 tests, longestmessage is 4531 chars |
Confirm that you want to switch languages
Your current edits will be lost.
Confirm that you wish to load a previous submission
Your current edits will be lost.