XOR Hero single-byte XOR, known-plaintext key recovery

crypto
flag L3m0n{1cd8fe934260b44140ef396a04dfadb2}

A 100-point guided lesson: "every bit of the flag was flipped with a single secret byte. Flip it back." The mission hands you the ciphertext in hex and a nudge: "the first byte is 16. XOR it with 4c."

output
1669376a34216b393e623c3f63696e686c6a386e6e6b6e6a3f3c69636c3b6a6e3e3c3b3e386827

Insight

Every L3m0n flag starts L3m0n{, which is known plaintext for the first 6 bytes. XOR the first ciphertext byte against the first plaintext byte and you have the single-byte key directly - no brute force required, but brute-forcing all 256 keys and checking for the L3m0n{ prefix is just as fast and doesn't rely on getting the hint's arithmetic right by hand:

python
1cipher = bytes.fromhex(
2    "1669376a34216b393e623c3f63696e686c6a386e6e6b6e6a3f3c69636c3b6a6e3e3c3b3e386827")
3
4for key in range(256):
5    plain = bytes(b ^ key for b in cipher)
6    if plain.startswith(b"L3m0n{"):
7        print(hex(key), plain.decode())
output
0x5a L3m0n{1cd8fe934260b44140ef396a04dfadb2}

Note

The lesson's own "real world" callout is worth repeating: XOR with a truly random key as long as the message, used exactly once, is the one-time pad - mathematically unbreakable. Shrink the key to one byte and reuse it across the whole message, and a 6-character known-plaintext crib is all it takes to recover it.