Dynamic Encoding: A CIA Mission


The Challenge Mission

You are Jim, a CIA agent in charge of super secret spies around the world. However, your enemies, the Naissurs, are highly trained in computer intelligence, and they can hack into your super secret communication systems. To contact your super secret spies, you must encrypt each message with a 16-character-long key. To encrypt a message, you must correspond each number of the key to each letter of the message. The number corresponding to each letter tells how many times to go ahead one letter. For example, if 3 corresponds to the letter a, we get a -> b -> c -> d and our new letter is d after encryption.


Key: 1111222233334444 Message: "Hello World"

Encrypted Message: "Ifmmq Yquog"

However, Naissurs have found your key time after time, and you find a way to have the key be dynamic. For this mission, you must create an encoder and decoder using this encryption method, such that the key is incremented every time the program decrypts a message.


Your program must take in the input e <message> for encoding, and d <message> for decoding. Your program also must generate a random 16-digit key upon running it. To set a key, you must be able to use the command s <key> to define the key.


Here is an example of the inputs and outputs of a program which generated the key 1111111111111111:

>e "Jim SMELLS Nice"


>d "Kjn TNFMMT Ojdf"


>s 0000000000000000

>e "Hello World"

Hello World!


This is code-golf, so the least amount of bytes wins the challenge solves the mission and is promoted!

Meow Mix

Posted 2015-10-23T00:04:00.257

Reputation: 823

Question was closed 2017-08-16T00:30:20.363

3We need test cases that contain a sequence of commands. – xnor – 2015-10-23T00:09:29.217

Related (not sure if similar enough to be a duplicate) – DLosc – 2015-10-23T00:12:32.850

@DLosc I'd say they're different enough. Different input format, numeric keys, random persistent keys, variable capitalization. – Mwr247 – 2015-10-23T03:10:59.830

2Can the number of characters in the message be longer than the key? If not, what to do with the characters after length 16 ? And why not also encode the spaces? (would be more secure) – LukStorms – 2015-10-23T19:49:51.457

implementing a crappy affine. hmmm...no thanks. – Chad Baxter – 2016-10-07T04:13:57.970

No answers