The goal is to decrypt 11 files.
What we know?
- The password contains 6 characters in lowercase from a-z.
- Files have been encrypted with a XOR
- There is a file which contains latin
In theory, there are 26^6 possibilities (308 915 776) but with what we know there are only 6 * 26 possibilities (152).
I used brut force and frequency analysis.
- I group ciphered bytes by key byte (e.g. key:
ABCand cipher:ABCDEF= A:(A,D); B:(B, E); F:(C, F) - For each key byte (6) and for each possibility (a-z):
- Decrypt grouped bytes with the possibility
- Frequency analysis of the message for each possible language
- Count the number of each letter in the message which we multiply by its weight (probability)
- Count the number of each unexpected char in the message which we multiply by its negative weight
- Pick the key byte possibility which produced the highest weight (more probable message)
- Decryption of the cipher with the key previously found.
- We check if the message contains at least 3 words of a dictionary
- If yes, we write the message in a new file
- If not, we assume the key found is wrong
npm install && npm run start