An XOR decoder combines each byte of the input with a key byte using exclusive-or (XOR). Because (x ⊕ k) ⊕ k = x, applying the same key twice gives back the original, so the same operation encrypts and decrypts.
Example
Leave Key empty to brute-force a single-byte key:
1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b37360x58 Cooking MC's like a pound of bacon
Best guess key: 0x58The ten most English-looking candidates are listed, best first. This one is challenge 3 of the well-known Cryptopals set.
How XOR encryption works
XOR compares two bits and returns 1 when they differ. Applied byte by byte with a key, it's the simplest symmetric cipher there is:
| Plaintext byte | Key byte | Result |
|---|---|---|
43 (C) | 58 | 1b |
6f (o) | 58 | 37 |
1b | 58 | 43 (C) |
- Single-byte XOR uses one key byte for the whole message. There are only 255 useful keys, so brute force is instant.
- Repeating-key XOR cycles through a key such as
key. It's broken like Vigenère: find the key length, then solve each position as a single-byte XOR. - XOR with a truly random key as long as the message, used once, is a one-time pad and can't be broken.
Malware often hides strings and configuration with single-byte or short repeating XOR keys, which is why this is a staple of CTFs and reverse engineering.
How to use the XOR decoder
- Paste the data as hex (the default) or switch Input as to Text.
- Leave Key empty to brute-force single-byte keys, or enter a key as text (
key) or hex (0x41or0x6b6579). - Read the result. The brute-force list is ranked by English letter frequency, so the right answer is usually on the first line.
XOR in code
data = bytes.fromhex("1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736")
print(bytes(b ^ 0x58 for b in data).decode()) # Cooking MC's like a pound of bacon
# repeating key
key = b"key"
print(bytes(b ^ key[i % len(key)] for i, b in enumerate(b"hello")).hex())At a glance
| Operation | Bitwise exclusive-or, byte by byte |
| Self-inverse | Yes: the same key decrypts |
| Single-byte key space | 255 keys |
| Weakness | Known plaintext reveals the key: key = plaintext ⊕ ciphertext |
Frequently asked questions
How do I find a repeating XOR key?
Guess the key length by computing the Hamming distance between blocks of the ciphertext for each candidate length; the right length gives the smallest normalized distance. Then split the ciphertext into that many columns and brute-force each column as a single-byte XOR.
Why does the brute force show several readable lines?
Keys that differ only in bit 5 (0x20) flip the case of letters, so 0x58 and 0x78 can both look readable. The ranking puts the most English-looking one first.
Can I XOR two hex strings together?
Paste the first string as the input and enter the second as a hex key with a 0x prefix. If the key is shorter than the data, it repeats.
Last reviewed · found a mistake? contact@decoder.tools · view as markdown