Category: crypto - Points: 25

The description is provided in the following file:

D4RKBLU3 is a novice cracker and is starting to learn the basics of Cryptography.
He comes across this encryption system which uses the following python function to encrypt data:
def enc(message, key):
    message = message.decode('hex')
    key = key.decode('hex')
    return (''.join(chr(ord(k)^ord(c)) for c,k in zip(message,itertools.cycle(key)))).encode('hex')
D4RKBLU3 used this function to encode the message "omg thisisfoobar" with two keys.

He tried devising a complex system which he claims cannot be broken.
He just provided us with the following flowchart and the final result after using 2 layer encryption.

             / \
      key1  /   \  key2
           /     \
          b       c
           \     /
      key2  \   /  key1
             \ /

    a = "omg thisisfoobar"
    d = "0b59154b16041c400e1c121f180c0416"

He used the above mentioned system in such a way that enc(b,c) gave out his password. Are you smart enough to find his password?

When we analyze the enc function, we discover that it just repeats the key to make it as long as the message and then xor the two.

From the image we can easily derive the definitions:

and also:

We need to get . Remembering that , we can do:

This means that we can just compute to get (the flag):

import itertools

def enc(message, key):

a = "omg thisisfoobar"
d = "0b59154b16041c400e1c121f180c0416"

# we need to encode *a* since it is then decoded by the function *enc*
print enc(a.encode('hex'), d)

This gives the following hex string:


which decodes to: