XOR Encrypt & Decrypt Online | Cipher Browser Brute Force Auto-Solve

Encryption
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.
⚠️ Critical Security: XOR encryption is NOT secure for real-world use unless the key is truly random, as long as the message, and used exactly once (one-time pad). Short repeating keys can be broken in seconds. Use AES-256 or ChaCha20 for actual encryption.

How It Works

What Is XOR Cipher?

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.

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 key bytes repeat over the input; enter it as text or hex, or click Random for a 16-byte key. Encrypt takes UTF-8 text and produces Base64 or Hex; decrypt reverses the process. When decryption produces invalid UTF-8, the result is shown as hex automatically.

When to Use XOR Cipher

  • Educational purposes — Understanding the fundamentals of symmetric encryption and stream ciphers
  • CTF challenges — Capture-the-flag competitions often feature XOR-based puzzles
  • Obfuscation — Simple data obfuscation (not encryption) for non-security-critical applications
  • One-time pad — The only theoretically unbreakable cipher, but requires a truly random key as long as the message
  • Building block for learning — Understanding how modern ciphers (ChaCha20, AES-CTR) use XOR internally
  • When NOT to use — For any real encryption needs, use AES-256-GCM or ChaCha20-Poly1305 instead

Attack Methods Reference

MethodKey TypeInput NeededSpeed
Brute ForceSingle byte (0-255)Ciphertext onlyInstant (256 tries)
Auto-solveMulti-byte repeatingCiphertext onlyFast (statistical)
Key RecoveryAny lengthCiphertext + known plaintextInstant (direct XOR)

Standards Compliance

  • XOR Operation — Fundamental bitwise operation in computer science
  • One-Time Pad — Information-theoretically secure when used correctly (Shannon, 1949)
  • Stream Ciphers — Modern ciphers (ChaCha20, AES-CTR) use XOR with cryptographically secure keystreams
  • NIST — XOR alone is not standardized for encryption; use AES or approved stream ciphers

Last updated:

Code Examples

XOR encrypt/decrypt in multiple languages:

JavaScript — Browser (Repeating Key)

// XOR with repeating key
function xor(input, key) {
  const out = new Uint8Array(input.length);
  for (let i = 0; i < input.length; i++) {
    out[i] = input[i] ^ key[i % key.length];
  }
  return out;
}

const text = new TextEncoder().encode('secret message');
const key = new TextEncoder().encode('key');
const ciphertext = xor(text, key);
console.log('Ciphertext (Base64):', btoa(String.fromCharCode(...ciphertext)));

// Decrypt (same operation)
const decrypted = xor(ciphertext, key);
console.log('Decrypted:', new TextDecoder().decode(decrypted));

Python — XOR with Repeating Key

def xor(data: bytes, key: bytes) -> bytes:
    return bytes(b ^ key[i % len(key)] for i, b in enumerate(data))

plaintext = b'secret message'
key = b'key'
ciphertext = xor(plaintext, key)
print(f'Ciphertext (hex): {ciphertext.hex()}')

# Decrypt (same operation)
decrypted = xor(ciphertext, key)
print(f'Decrypted: {decrypted.decode()}')

Go — XOR Cipher

package main

import (
    "encoding/hex"
    "fmt"
)

func xor(data []byte, key []byte) []byte {
    result := make([]byte, len(data))
    for i, b := range data {
        result[i] = b ^ key[i%len(key)]
    }
    return result
}

func main() {
    plaintext := []byte("secret message")
    key := []byte("key")
    
    ciphertext := xor(plaintext, key)
    fmt.Printf("Ciphertext (hex): %s\n", hex.EncodeToString(ciphertext))
    
    // Decrypt (same operation)
    decrypted := xor(ciphertext, key)
    fmt.Printf("Decrypted: %s\n", decrypted)
}

Rust — XOR Encryption

fn xor(data: &[u8], key: &[u8]) -> Vec<u8> {
    data.iter()
        .enumerate()
        .map(|(i, &b)| b ^ key[i % key.len()])
        .collect()
}

fn main() {
    let plaintext = b"secret message";
    let key = b"key";
    
    let ciphertext = xor(plaintext, key);
    println!("Ciphertext (hex): {:?}", ciphertext.iter().map(|b| format!("{:02x}", b)).collect::<Vec<_>>().join(""));
    
    // Decrypt (same operation)
    let decrypted = xor(&ciphertext, key);
    println!("Decrypted: {}", String::from_utf8(decrypted).unwrap());
}

Node.js — XOR with Buffer

function xor(data, key) {
    const result = Buffer.alloc(data.length);
    for (let i = 0; i < data.length; i++) {
        result[i] = data[i] ^ key[i % key.length];
    }
    return result;
}

const plaintext = Buffer.from('secret message', 'utf8');
const key = Buffer.from('key', 'utf8');

const ciphertext = xor(plaintext, key);
console.log('Ciphertext (hex):', ciphertext.toString('hex'));

// Decrypt (same operation)
const decrypted = xor(ciphertext, key);
console.log('Decrypted:', decrypted.toString('utf8'));

Common Pitfalls & Attack Vectors

⚠️ Using Short Repeating Keys — A short repeating key can be broken in seconds using frequency analysis or brute force. Single-byte keys require only 256 attempts.
⚠️ XOR for Real Encryption — XOR alone is NOT secure for real-world encryption. Use AES-256-GCM or ChaCha20-Poly1305 for actual encryption needs.
⚠️ Key Reuse — Reusing the same key for multiple messages allows attackers to XOR ciphertexts together, eliminating the key and revealing patterns in the plaintext.
⚠️ Predictable Keys — Using passwords, phrases, or non-random data as keys makes XOR trivially breakable. Keys must be truly random for any security.
⚠️ Misunderstanding One-Time Pad — A one-time pad requires a truly random key as long as the message, used exactly once. Any deviation breaks the security guarantee.

Security Notes

🔒 XOR is not secure for real encryption — a short repeating key can be broken in seconds with frequency analysis or brute force.
🔒 One-time pad is the only secure XOR — requires a truly random key as long as the message, used exactly once; impractical for most use cases.
🔒 Use AES or ChaCha20 instead — modern stream/block ciphers use XOR internally but with a cryptographically secure keystream that cannot be predicted or brute-forced.
🔒 XOR is great for learning — understanding XOR cipher fundamentals is essential for cryptography education and CTF challenges.

Disclaimer

Disclaimer: This page is for educational and CTF purposes only. It does not constitute professional security advice. XOR encryption is NOT secure for real-world use. For production encryption, use AES-256-GCM or ChaCha20-Poly1305 and consult official standards (NIST, IETF).

Further Reading & Standards

Related Concepts

Related Tools

Need real encryption? Try AES Encrypt/Decrypt for NIST-standard security or ChaCha20 Encrypt/Decrypt for a modern stream cipher. For generating strong keys, the Password Generator creates cryptographically secure random strings.

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 is not secure and can be broken in seconds. Use XOR for learning and CTF puzzles; use AES or ChaCha20 for real security.

How does the brute-force panel work?

For single-byte keys, the tool tries all 256 possible key values and shows each decryption result. Look for readable text in the output — the correct key produces intelligible plaintext. This works instantly in your browser.

What does Auto-solve do?

Auto-solve uses statistical analysis (index of coincidence + frequency analysis) to crack multi-byte repeating-key XOR automatically. It finds the key length first, then solves each key position. No key input needed — just paste the ciphertext.

What input formats are supported?

Encrypt takes plain text (UTF-8) and produces Base64 or Hex output. Decrypt takes Base64 or Hex ciphertext and returns plain text. The key can be entered as text or hex in both modes. If decryption produces invalid UTF-8 (wrong key), the result is shown as hex automatically.

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).

Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.

More in Encryption