decoder.tools

XOR Cipher Decoder

XOR bytes with a key, or try all 255 single-byte keys and rank the results by how readable they are.

INPUT
OUTPUT

The result appears here as you type.

Decoding runs in your browser. What you paste is not sent to a server.

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:

Input
1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736
Output
0x58  Cooking MC's like a pound of bacon
Best guess key: 0x58

The 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 byteKey byteResult
43 (C)581b
6f (o)5837
1b5843 (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

  1. Paste the data as hex (the default) or switch Input as to Text.
  2. Leave Key empty to brute-force single-byte keys, or enter a key as text (key) or hex (0x41 or 0x6b6579).
  3. 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

Python
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

OperationBitwise exclusive-or, byte by byte
Self-inverseYes: the same key decrypts
Single-byte key space255 keys
WeaknessKnown 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