Previous Level: Level 2
Login
SSH: ssh krypton3@krypton.labs.overthewire.org -p 2231
Task
In the previous exercise you were able to introduce arbitrary plaintext to expose the key. In this example, the cipher mechanism is not available to you, the attacker.
However, you have been lucky. You have intercepted more than one message. The password to the next level is found in the file ‘krypton4’. You have also found 3 other files. (found1, found2, found3)
You know the following important details:
- The message plaintexts are in English (*** very important)
- They were produced from the same key (*** even better!)
A little bit of Theory
The problem with using one key repeatedly on a block of letters is that there will be a pattern. The more text will be encrypted with the same key the easier it is to find the pattern. Meaning, for different languages we can guess the key based on looking at the character with the biggest amount and assuming it is the character that is used most often in the English language. Quick googling will tell us that is the letter ’e’. This is based on the letter frequency and its entropy. It is used to do Frequency analysis. This is a method to break classical ciphers. Basically, you just count all letters (sometimes also combinations of letters) and based on how often they appear you assign them in order of the most frequent letters of the language.
Solution
We start by looking at the folder.
|
|
Looking at the ‘README’ and ‘foundX’ files, we have some ciphertext. We use frequency analysis to figure out the plaintext.
For each letter (for i in {A..Z}
), we take all their occurrences (tr -cd $i
) of all three files (cat found1 found2 found3
) and then count the characters (wc -c
).
|
|
Now, we just make the print nicer and sort the output (sort -nr
) with the highest occurrences first:
|
|
Now, we see that the letter S appears most often with 456 occurrences. So let’s assume the encryption is ‘E -> S’ (because ‘E’ is the most frequent letter in English). Now we look for a frequency list of letters for the English language online and get:
- Freq list: ETAOINSRHDLUCMFYWGPBVKXQJZ
- Cipher text: SQJUBNGCDZVWMYTXKELAFIORHP
Lastly, we map these letters to each other (like in previous levels):
|
|
We can see based on the result that does not work. Now, we could look at the relationship between letters. The website https://www3.nd.edu/~busiforc/handouts/cryptography/cryptography%20hints.html has some hints. However, I just tried slightly changing the order of the frequent list until the small text made sense. The frequency is just an approximation. It is not guaranteed to be exactly the right order, especially because it is just a small text we have to count. This is obviously because it depends on the variation of letters/words used in the text that we analyse. So here is the correct order:
|
|
https://overthewire.org/wargames/krypton/krypton3.html
Next Level: Level 4