XOR Cipher
Encrypt or decrypt bytes with an XOR key using text, hex, Base64, binary or decimal, with random keys and a byte-by-byte inspector.
Loading the XOR tool…
XOR is symmetric: Encrypt and Decrypt run the same operation. The tabs just swap the input and output formats and carry your result across.
Byte inspector
Add valid input and a valid key to see how each input byte is XORed with the repeated key bytes.
Highlighted output bits (1, bold and underlined) were flipped because the key bit is 1. K[n] shows which key byte was used.
| # | Input byte | ⊕ Key byte | = Output byte |
|---|---|---|---|
Using This Tool: Guide & Notes Show guide
The XOR cipher combines input bytes with repeating key bytes. The same operation encrypts and decrypts when the same key is used.
How to use it
- Choose Encrypt or Decrypt. XOR is the same operation in both directions. Switching with a valid result carries the output back to the input so you can check the round trip.
- Select text, hex, Base64, binary or decimal independently for the input, key and output.
- Enter a key, or choose a random key length and press Random key. Match input length generates one key byte per input byte. A shorter key repeats; surplus key bytes are unused.
- Use the byte inspector to see which key byte (K[n]) is used at each position. Bold, underlined output bits show which bits the key flipped. Show more expands the initial 64 rows up to 1,024 without truncating your actual output.
- Copy the input or output, save the displayed representation as a .txt file, or save the exact output bytes as .bin. Binary download remains available even when the bytes cannot be displayed as UTF-8 text.
Options and settings
- Text uses UTF-8. Invalid UTF-8 output is not silently replaced with placeholder characters: choose Hex or Base64 instead. Invisible control characters trigger a warning. Textareas normalise line endings; use Hex for exact CR or CRLF bytes.
- Hex accepts spaces, colons, hyphens, commas, 0x prefixes and backslash-x byte escapes. Binary accepts complete eight-bit bytes with optional spaces, underscores or 0b prefixes. Decimal accepts values 0–255 separated by whitespace or commas.
- Base64 accepts standard and URL-safe alphabets, whitespace and valid unpadded input. Malformed padding and non-zero padding bits are rejected.
- Group hex/binary bytes and uppercase hex output change presentation only. Moving an unsafe text result back to the input falls back to Hex to preserve the bytes.
- Input and key are each limited to 1 MiB of decoded bytes and 10 MiB of encoded characters. Large edits are debounced; the byte inspector never renders more than 1,024 rows.
- Random keys use the browser cryptographic random generator and are shown as Hex. No inputs, keys or results are uploaded or saved to browser storage. Downloaded files and clipboard contents contain your data.
Notes
- Repeating-key XOR is not secure modern encryption.
- A one-byte XOR key is especially weak and is mainly useful for demonstrations and puzzles.
- A key covering the input is not automatically a one-time pad. Perfect secrecy requires a genuinely random, secret key at least as long as the message, used only once. XOR alone does not authenticate the message or detect deliberate tampering.
- To XOR two byte streams, use one as input and one as the key, with their formats set correctly. Equal lengths prevent repetition; extra key bytes are ignored. For practical password-based protection, use the File & Message Encryptor instead.
XOR Cipher: The Tiny Bit Operation Behind Real Cryptography
How one simple either-or rule turns text into bytes, bytes into ciphertext, and classical cipher thinking into the logic of stream ciphers, one-time pads, and modern encryption.