Programming mission 2

Posted by Marcus - October 27, 2015

Analyze the picture and find the ascii code

The task is to extract a hidden message from an image within a 15 second time window. 

A hidden message?

My approach

We start by loading the image into Python.

img = np.array(Image.open('www.hackthissite.png'))

We then flatten the array into a list

img_flat = np.reshape(img,n_col*n_row)

Now we want to detect all the white pixels in the image.

wp_index = np.where(img_flat == 1)[0]

As stated at the website, the first character should remain the same, then the second should be wp_index[1]-wp_index[0].

wp_dist = [wp_index[0]]
for i in np.arange(len(wp_index)-1)+1:
    wp_dist.append(wp_index[i]-wp_index[i-1])

With this, we can convert the spacings into morse code (ascii characters) using the built in chr function in python. 

morse_code = []
for i in xrange(len(wp_dist)):
    morse_code.append(chr(wp_dist[i]))

After some cleaning up we now have the final morse code 

['.-', '-..-', '--...', '-..', '-----', '--...', '-....', '..-.', '-..-', '.', '']

The only thing left is to decode this, which is done like so 

morse_solved = []
for i in xrange(len(morse_final)):
    morse_solved.append(min(decode(morse_final[i]),key=len))

print "".join(morse_solved)

which gives an output like this 

AX7D076FXE

Simply copy that into the answering field and that's it!
Again, 15 seconds was enough for me to do this semi manually, so it can be done as simple as this!

The full code for this mission can be found at Github.