247CTF - Tips And Tricks
Recover a XOR encryption key used to encrypt a JPG image.
Approach
XOR encryption is vulnerable when the plaintext is partially known:
- JPG files have a known magic header:
FF D8 FF E0 00 10 4A 46 49 46 00 01 - XOR the encrypted header with known plaintext to recover the key
- Apply the recovered key to decrypt the entire file
Solution
1 | #!/usr/bin/env python3 |
Key Insight
The script assumes this exact JFIF header and a 12-byte repeating XOR key. A known header recovers only the keystream at those positions; JPEG variants can have different markers, and a longer key cannot be recovered from these bytes alone. The real encrypted attachment and key period are unavailable, so only a synthetic 12-byte-key round trip was checked.