XOR Cipher
Bitwise XOR of message and key; XOR again with k to decrypt.
Formula
Variables
Example
1 XOR 1 = 0; applying key twice returns the message
How it works
The formula c = m \oplus k means each bit of the message is combined with a key bit using XOR: matching bits produce 0, different bits produce 1. This works for simple encryption because XOR is its own inverse, so applying the same key again undoes the change and recovers the original message. In practice, this is the core idea behind many stream ciphers and one-time-pad style encryption, where a key stream is mixed with data one bit at a time.
When to use it
Use this when studying or implementing simple bit-level encryption, especially in stream ciphers, toy cryptography examples, or checking how reversible masking works. It is also useful whenever you need to flip selected bits in data using a key or mask.
Worked example, step by step
Message bit m = 0 Key bit k = 1 Compute ciphertext: c = m \oplus k = 0 \oplus 1 = 1 Decrypt by XORing again with the same key: 1 \oplus 1 = 0 Recovered message = 0
Common mistakes to avoid
- Thinking XOR always means addition; it is a bitwise operation, not normal arithmetic
- Forgetting that decryption uses the same key bit sequence as encryption
- Assuming XOR by itself is secure; without a strong secret key stream, it is easily broken
Did You Know?
A one-time pad — XOR with a truly random key as long as the message — is the only cipher proven unbreakable.
Share this formula
More in Cryptography & Security
View allModular Exponentiation
IntermediateCore operation of RSA encryption — raise a message to a power, modulo n.
RSA Decryption
AdvancedRecovers the message using the private exponent d.
Euler's Totient
IntermediateCounts integers below n coprime to it, for n = pq — used to make RSA keys.
Shannon Entropy
AdvancedAverage information content — and the theoretical strength of a random source.
Password Entropy
IntermediateBits of security from password length and character-set size.
Key Space Size
IntermediateNumber of possible keys for a b-bit key.