XOR Cipher
An XOR cipher combines message bits with key bits using exclusive OR; applying the same key again recovers the message. Reusing key bytes exposes relationships between messages. Repeating-key XOR is not secure encryption on its own.
How to use XOR Cipher
- Pick Encrypt (text → hex) or Decrypt (hex → text).
- Enter a text key. Its UTF-8 bytes repeat across the message.
- Enter text to encrypt, or paste hex ciphertext to decrypt. Hex input ignores whitespace and requires complete byte pairs.
- Read or copy Result. If decrypted bytes are not valid UTF-8, Result contains hex and a warning explains why.
Encryption uses UTF-8 bytes for both text and key. Hex output uses lowercase letters and 2 digits per byte, preserving leading zeroes. All messages below are labeled assumed example; their results are calculated from the same codec as the tool.
XOR truth table
Exclusive OR sets a result bit when the input bits differ and clears it when they match. Apply this rule independently to every bit in a byte.
| a | k | a ^ k |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
Worked example: HELLO with key KEY
assumed example: message HELLO, key KEY. These ASCII characters each occupy a UTF-8 byte. The table shows 8-bit groups and the repeating key aligned with the message.
| Character | Hex | Binary | Key character | Key binary | Result binary | Result hex |
|---|---|---|---|---|---|---|
| H | 48 | 01001000 | K | 01001011 | 00000011 | 03 |
| E | 45 | 01000101 | E | 01000101 | 00000000 | 00 |
| L | 4c | 01001100 | Y | 01011001 | 00010101 | 15 |
| L | 4c | 01001100 | K | 01001011 | 00000111 | 07 |
| O | 4f | 01001111 | E | 01000101 | 00001010 | 0a |
Join the result hex pairs without spaces: 030015070a. Hex is a representation of these bytes; it does not add secrecy.
How a short key repeats
assumed example: HELLO WORLD is 11 bytes; KEY is 3 bytes. Restart the key as often as needed and stop when the message ends.
Message: HELLO WORLD
Key: KEYKEYKEYKE
Key bytes (hex): 4b45594b45594b45594b45
Ciphertext: 030015070a791c0a0b0701
Repetition uses UTF-8 byte positions, not displayed character positions. Non-ASCII letters can occupy multiple bytes. A longer typed password still does not turn this repeating-key operation into a secure encryption scheme.
Decrypting and why the same key works
XOR twice cancels: a ^ k ^ k = a. A bit toggled by the key toggles back on the next application; a bit left unchanged stays unchanged. The key bytes must start at the same position.
assumed example: decrypt 030015070a with KEY to recover HELLO. The recovered bytes are 48454c4c4f in hex. Select Decrypt and paste the ciphertext; entering the hex digits in Encrypt would encrypt those literal characters instead.
Wrong key and what the tool shows
A wrong key does not always cause a text-decoding error. Valid UTF-8 is a format check, not proof of the correct key or an authentic message.
assumed example: key BAD
Ciphertext: 030015070a. Result bytes (hex): 414151454b.
Valid UTF-8: yes. Result field: AAQEK.
No warning is shown: these bytes decode to text, even though this is not the assumed original message.
assumed example: key é
Ciphertext: 030015070a. Result bytes (hex): c0a9d6aec9.
Valid UTF-8: no. Result field: c0a9d6aec9.
Warning: These bytes are not valid UTF-8 text. The key is probably wrong.
The tool identifies Result as decrypted bytes in hex, so you can still copy the data.
Why key reuse and short keys are weak
The same key stream cancels between messages
For messages encrypted with the same aligned key stream, Ca ^ Cb = (Pa ^ K) ^ (Pb ^ K) = Pa ^ Pb. This reveals a relationship between plaintexts, even without knowing the key. It does not automatically reveal both messages.
assumed example: HELLO with key KEY → 030015070a.
assumed example: WORLD with key KEY → 1c0a0b0701.
Ciphertext XOR: 030015070a ^ 1c0a0b0701 = 1f0a1e000b
Plaintext XOR (hex): 1f0a1e000b
A known plaintext guess reveals key bytes
assumed example: GO HOME with key SUN gives 141a6e1b1a0316. Suppose an observer guesses HOME at byte offset 3, counting from zero. XOR that guess with the corresponding ciphertext segment:
1b1a0316 ^ 484f4d45 = 53554e53 (SUNS)
If the guess and position are correct, these are the key-stream bytes at those positions. In this assumed example they span the repeating key and its restart. An incorrect guess yields only a candidate key segment.
A single-byte key has 256 possibilities
An unrestricted 8-bit key byte has 256 possible values. Trying them all is a small search, though choosing the intended plaintext still requires context. This count describes raw byte keys; the tool accepts a UTF-8 text key, so arbitrary byte values cannot all be entered as single characters.
assumed example: HELLO with text key K (hex 4b) gives 030e070704. Longer repeating keys reuse the same byte at regularly spaced positions, exposing patterns that can be analyzed together.
Where XOR genuinely appears
- Stream ciphers combine plaintext with a generated keystream using XOR. Their security depends on the keystream construction and correct use, not on the XOR operation alone.
- A one-time pad uses a truly random, secret key independent of the message, as long as the message and used only once. Under those conditions it provides perfect secrecy. A repeated text key does not meet them.
- Parity calculations and simple XOR checksums combine bits to help detect some errors. They do not provide cryptographic authentication.
A short history
Gilbert Vernam’s 1919 patent US 1,310,719, “Secret signaling system,” describes a stream-cipher machine that combines telegraph message signals with a key tape and reverses the combination at the receiver. See Vernam’s patent on Google Patents.
Claude Shannon’s 1949 paper “Communication Theory of Secrecy Systems” formalized perfect secrecy and proved that the one-time pad achieves it under its random, single-use key assumptions. See Shannon’s paper, hosted by Wesleyan University. This result does not apply to a short repeating key.
Frequently asked questions
Is XOR encryption secure?
Repeating-key XOR is not secure encryption on its own. Short keys expose patterns, and reusing the same key stream lets an observer cancel it by XORing ciphertexts. This tool is for learning; it does not authenticate messages.
What does XOR mean?
XOR means exclusive OR. Each result bit is set when the corresponding input bits differ, and cleared when they match. This tool applies that operation to UTF-8 bytes of the text and key.
Why does the same key decrypt?
XOR is its own inverse: a ^ k ^ k = a. Apply exactly the same key bytes at exactly the same positions to recover the original bytes.
What if the key is shorter than the message?
The key repeats from its first UTF-8 byte until the message ends. Repetition follows byte positions, which may differ from character positions for non-ASCII text.
Why does my decrypt show garbled text or an error?
A wrong key can produce valid UTF-8 that is meaningless, so readable output does not prove the key is correct. If the bytes are not valid UTF-8, the tool reports that the key is probably wrong and shows the resulting bytes as hex. Malformed hex input produces a separate error.
Can I XOR hex with hex?
This tool accepts text and a text key for encryption and returns hex. For decryption it accepts hex ciphertext and a text key, then returns UTF-8 text or raw hex if the result is not valid UTF-8. It does not accept a hex-encoded key; typing hex digits in Key uses those literal text characters.
How is XOR different from Vigenere?
XOR combines bits of bytes, while the classical Vigenere cipher shifts letters using modular alphabet arithmetic. Both can use repeating keys, but their operations and outputs differ; neither repeating-key scheme is suitable for protecting sensitive messages.
Is my data sent to a server?
No. The interactive XOR conversion runs in your browser; your input and key are not sent to a server by this tool.