XOR Encrypt/Decrypt

Encryption

Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.

How It Works

XOR (exclusive OR) is the smallest possible cipher: every byte of the message is combined with a key byte using the XOR operation. It is the building block that real ciphers are made of — ChaCha20 and AES-CTR are, at their core, XOR against a cryptographically secure keystream. This tool lets you work with the raw operation directly, and everything runs locally in your browser.

How It Works

  • Encrypt and Decrypt are the same operation: XOR is its own inverse (a ⊕ b ⊕ b = a) — applying the key to the ciphertext returns the plaintext. The tool keeps the familiar Encrypt/Decrypt modes so your intent is explicit, but internally both run the identical XOR. Use Swap to flip the mode and move the output into the input for instant verification.
  • Repeating key: The key bytes repeat over the input (key byte 1, 2, 3... then back to 1). Enter it as plain text or hex. The Generate button creates a random 16-byte key with your browser’s cryptographic random number generator.
  • Formats: Encrypt takes plain text (UTF-8) and produces Base64 or Hex; Decrypt takes Base64 or Hex ciphertext and returns plain text. The key works as text or hex in both modes. When a decryption result is not valid UTF-8 (wrong key or binary data), it is automatically shown as hex instead of garbled characters.

Why Reused-Key XOR Fails — Try It Yourself

The three attack panels below the tool are not gimmicks: they demonstrate exactly why XOR with a short key is not encryption.

  • Single-byte brute force: If the key is one byte, there are only 256 possibilities. The tool tries them all and ranks the candidates by how much readable text they produce. Any single-byte-XOR message falls in milliseconds.
  • Auto-solve (repeating keys): For longer keys, the panel estimates the key length from the ciphertext’s statistics (index of coincidence) and then solves each key position by English letter frequency — the classic Cryptopals attack, fully automated. If the guess is off, pick another length from the candidates.
  • Known-plaintext recovery: Because key = ciphertext ⊕ plaintext, knowing (or guessing) a fragment of the message reveals the key directly. This is why keys must never be reused across messages.

The One-Time Pad

XOR becomes unbreakable when the key is truly random, at least as long as the message, and used exactly once — Claude Shannon proved this gives perfect secrecy in 1949. It is the only cipher with that guarantee, and also wildly impractical: distributing keys as long as the messages is harder than keeping the messages secret. That trade-off is why real systems use AES or ChaCha20 with a short key instead. Use this tool to build intuition; use those for actual security.

Frequently Asked Questions

Is XOR encryption secure?

Only under one exact condition: the key must be truly random, at least as long as the message, and used exactly once — a one-time pad. XOR with a short repeating key (a password) is not secure and can be broken in seconds with frequency analysis, brute force, or known-plaintext techniques. Use XOR for learning and CTF puzzles; use AES or ChaCha20 for real security.

What is a one-time pad (OTP)?

A one-time pad is XOR encryption with three strict requirements: the key is perfectly random, the key is at least as long as the message, and the key is never reused. Under these conditions XOR achieves perfect secrecy — the ciphertext reveals zero information about the plaintext, proven by Claude Shannon in 1949. Drop any one requirement and the security collapses.

Why is XOR its own inverse?

XOR has the property that a XOR b XOR b = a. Applying the same key twice cancels itself out: plaintext XOR key gives the ciphertext, and ciphertext XOR key gives back the plaintext. The tool presents separate Encrypt and Decrypt modes for clarity, but both run this identical operation — which is also why the Swap button can flip direction instantly.

How do I break a repeating-key XOR?

For single-byte keys, brute force all 256 possibilities and look for readable text — this tool automates it in the Single-byte brute force panel. For multi-byte repeating keys, statistical methods (index of coincidence, then per-position frequency analysis) crack it: find the key length first, then solve each key position. The Auto-solve panel does this end-to-end; if you already know a plaintext fragment, the Key recovery panel gets the key directly (key = ciphertext XOR plaintext).

What input and key formats are supported?

Encrypt mode takes plain text (UTF-8) and produces Base64 or Hex. Decrypt mode takes Base64 or Hex ciphertext and produces plain text. The key can be text or hex in both modes. If a decryption result is not valid UTF-8 — a wrong key, or binary data — the tool automatically shows it as hex instead of garbled characters.

Is my data sent anywhere?

No. All XOR operations run locally in your browser with plain JavaScript — there is no backend server, no network request, and no tracking of your input. Your data never leaves your device.

Privacy Note

This tool runs entirely in your browser. Your input is never uploaded, stored, or sent to any server.

Disclaimer: This tool is provided for educational and informational purposes only. The results do not constitute professional security advice. Use at your own discretion.

More in Encryption