Thursday, February 4, 2016

Set 1 - Challenge 3

Original Challenge Description from matasano

Single-byte XOR cipher

The hex encoded string:
1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736
... has been XOR'd against a single character. Find the key, decrypt the message.
You can do this by hand. But don't: write code to do it for you.
How? Devise some method for "scoring" a piece of English plaintext. Character frequency is a good metric. Evaluate each output and choose the one with the best score.

  • Need a program to brute-force xor with one  byte to produce the output.
  • Then we can visually go through the output to see whats makes sense and/or also write anther program to check if the output is English based on the letter frequency

My Solution


  • Here is the brute-force program




OK,  MAXLINE is not really for the lines but this will crash if given bigger input.

Now lets run this program against the given input and see what the output looks like



Most of the output is not printable but below chunk seems interesting.

Although bacon is not my thing but you can see the most probable message here 

Now lets  write a program to do the scoring for English and see if it picks up the one seen above.





Weight is given to most common English letters and then other alphabets and the program prints the max score and some other stuff. This may have to be modified later.

Now run the earlier program through our scoring engine and see if it gets the food.
I modified the brute-force  program a bit to output the xor byte



Now, can not wait to tweet!

No comments:

Post a Comment