ASCII Decryption

ASCII Decryption

In this challenge you must decrypt a message which contains numbers. Each number is obtained by taking an ASCII code of the original character and adding some unknown constant N.

For example, you can encrypt the word ‘test’ with the condition that N = 11.
‘test’ to ASCII -> 116 101 115 116 -> add N to each number-> 127 112 126 127

In the encrypted message, only words are encrypted with the unknown constant. The blank space character remains unaffected by the constant.

For example, you can encrypt the message ‘some word’ with the condition that N = 11.
‘some word’ to ASCII ->115 111 109 101 032 119 111 114 100 -> add N to each number that is a word-> 126 122 120 112 032 130 122 125 111
Notice that the number 32 representing a blank space, remains unchanged.

You know that the original message includes two identical words consisting of X characters and you know the last letter in the word. Each line of input consists of three parts: length of a word, which is repeated twice, the last letter of this word, and an encrypted message separated with space. Using this information, decrypt the message.

Example 1:


input data:
5 | s | 92 112 109 32 118 109 109 108 123 32 119 110 32 124 112 109 32 117 105 118 129 32 119 125 124 127 109 113 111 112 32 124 112 109 32 118 109 109 108 123 32 119 110 32 124 112 109 32 110 109 127 54 32 53 32 91 120 119 107 115
output:
The needs of the many outweigh the needs of the few. - Spock 

Example 2:


input data:
2 | o | 075 032 099 110 121 099 123 117 032 116 103 111 103 111 100 103 116 032 118 113 032 102 113 032 111 123 032 106 113 111 103 121 113 116 109 046 32 102 113 32 123 113 119 065
output:
I always remember to do my homework, do you? 

Credits: This is a modification of this CodeEval challenge.

Seda
Seda Kunda is a web designer and developer with a degree in Computer Science and a great passion for code. Besides code, she enjoys pepperoni pizza, watching the bachelor and sleeping in on Saturdays.
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn