BruCON 2023 CTF Crypto Challenge
Crypto: Dragon’s Crib
Our team spent considerable time on this challenge, which only provided 50 points in the end. True, it was easier than I had expected, but still I think it deserved more points.
We are provided with an encryption algorithm, implemented in Python, and 5 ciphertexts:
|
|
In this program, the plaintext is XORed with a random byte. Note the program has an error: it’s not randint(0,256)
because this can produce 256 which no longer fits in a byte. Rather it should be randint(0,255)
. I went to see the organizers about this, they confirmed the issue but commented it would not pose a problem to solve the challenge. So, just think we have randint(0,255)
.
Those are the provided ciphertexts:
|
|
Second we notice that the encryption starts by seeding the random generator. So each ciphertext will be XORed by the same sequence of bytes. And this is inherently insecure: XOR is solid as long as the key is never reused…
Then, we imagined we could work out the sequence of bytes. We thought we could bruteforce all seeds and test whether the ciphertext would decrypt to correctly readable text. However, there are 2**32 possible seeds, and while not huge, this is absolutely too long to be bruteforced by our laptops (we tried…).
The solution was to find how to break this knowing that we had several ciphertexts. A team mate spotted this website. The name is close to the title of the challenge, so it looks like it’s the correct direction.
Actually this other website does the same but easier to use IMHO. How do you use this website? On the left, you put one ciphertext, on the right another one. For example the first and the fifth. Then you need to guess character by character what the first line contains and see the result at the same time for the fifth line, which guides you as to which characters should be correct in the crib word.