P

R

O

G

R

A

M

M

I

N

G

 

C

O

M

P

E

T

I

T

I

O

N

 

Encryption Analyst

Task #8

Novice/Advanced

8 Points

Task Description
You’ve been contracted by your country’s Intelligence Agency to decode a message that was intercepted by an operative in a foreign country. Your mission 008, should you decide to accept it, is to write an algorithm that processes an input data file and determines the encryption key. This key will be an 8-bit value.

Program Input
The input file will be encrypted and will consist of a list of values each ranging from 0-255, separated by commas and/or Carriage Returns/Linefeeds. You will need to apply an encryption key value ranging from 0-255 to each byte of the message and search on the keyword ‘Codewars4’ (ignore case). When you have encountered this keyword, then you will have your encryption key and be able to decode the message. Each byte will then represent standard ASCII characters (ie-65=’A’, 66=’B’, 67=’C’, etc.).

Decryption Algorithm
The operative who intercepted the message was also able to obtain the decryption algorithm. Luckily for your country, he was able to send it, along with the message, just before they disappeared. The algorithm adds the encryption key to the first byte, adds the encryption key plus 1 to the second byte, adds the encryption key plus 2 to the third byte, and so on. When the (encryption key plus increment) reaches 255, the next value will be 0. Each byte is then masked to obtain final values that range from 0-255.

138,165,174,173, 162,167,165, 86, 92,119,162,150,150,135,144,160,

160, 96, 82,100, 73,113,149, 156,134,151,140,145,143, 64,150,135,

137,136, 59,137,124,123,140,136, 53,122,133,129,126, 48,131,118,

114, 44, 89, 97, 55, 40, 73,127, 37, 55, 68, 79, 45, 32,118, 99,

29, 97, 115,106, 94, 91,107, 0, 91,105, 95, 94, 17, 85, 93, 98,

95, 77, 91, 87, 78, 86, 91, 6, 84, 74, 3, 86, 73, 69,255, 63,

65, 82, 64, 76, 76, 57, 73, 79, 3,222,221

Example: With an encryption key of 0xC3, do the following to the input data:
1. The first decrypted value will be (((0xC3 + 0) & 0xFF) + 138) & 0xFF) -> 0x4D (‘M’)
2. The second decrypted value will be (((0xC3 + 1) & 0xFF) + 165) & 0xFF) -> 0x69 (‘i’)
3. The third decrypted value will be (((0xC3 + 2) & 0xFF) + 174) & 0xFF) -> 0x73 (‘s’)
4. The forth decrypted value will be (((0xC3 + 3) & 0xFF) + 173) & 0xFF) -> 0x73 (‘s’)
5. And so on…

Program Output
Upon decryption, the output will be a simple text message that will save your country. Simply output the encryption key followed by the message as follows to an output file. Be sure to account for word wrap such that no line has more than 80 characters, and no words are split between lines.

Encryption Key = 0xC3
Mission 'CodeWars4': Invasion will occur from the NW. By 3AM, we expect
full entrapment of the adversary.