# ENOWARS 2011 CTF Write-up: Diary

The challenge consists of the following description:

Hey! I am sure, Dark Viewer is writing down every little poop he did. Just trying to get the infos by searching for his diary. Shit. Its encrypted but what is the key…
Lets try break it!!

and this ciphertext: diary

Despite being only 100pts worth, no team was able to solve this challenge during the CTF, so a hint was added:

Tip: Two very simple encryptions on top of each other.

Using our tool charemap, we can perform a quick analysis of the ciphertext:

We notice that the most frequent char is r followed by g. The distance (modulo 26) between r and e is 13; the same holds for g and t and so on:

We can safely assume that the first encryption used is ROT13.

Now, ROT13 is a basic form of a substitution cipher, so E = substitution(ROT13(M)) = substitution'(M). It would be just one substitution in the end. Concerning the encryption on top of rot13, we can exclude the vigenere cypher because the frequency of chars is very close to a typical English language text. So, what is a well known cipher that only scrambles the text? The columnar transposition cipher ðŸ™‚

Looking deeper at the ciphertext we notice a good degree of regularity. We focus on some sequences of numbers that look like pieces of the flag (remember that the flag format is eno[a-z0-9]{37}). Starting from the end, we calculate the distance between these 7 substrings:

At this point, we know that there are 7 subsets of flag chars at a distance of ~269 chars between each one of them.

We calculate the char number of diary_rot13.txt to see if it’s possible that the columnar transposition cipher is implemented with 7 columns and 269 rows:

Yes! But it looks like there is one column with one char more than the others (the first column before scrambling). This leads to an irregularity in the transposition cipher.

Now it’s just a matter of finding the column with 270 rows and the correct permutation of columns. We can guess that the last char of the plaintext is a vertical tab. In this case it will be placed in the second column. At this point, finding the right permutation is trivial. We use the following code to decrypt the message:

With this script, we get the deciphered text and the flag!

## Author: Marco Squarcina

Computer Science student and an Open Source enthusiast. My main interests are computer security (especially mandatory access control systems), Linux systems administrations and audio applications.