> XOR CIPHER
The idea in plain English: XOR stands for "exclusive OR." Imagine flipping a light switch — but with a rule: the light turns on ONLY when exactly one switch is up (not both). That's XOR. In binary (0s and 1s), XOR outputs 1 when the two inputs are different, and 0 when they're the same. To encrypt text, you take each letter's numeric code and XOR it with a secret key byte. The magic trick: XOR the encrypted result with the same key again, and you get back the original. Same operation encrypts AND decrypts.
▸ Visual: XOR Gate Logic
Why this really exists: XOR is the foundation of modern block ciphers like AES (Advanced Encryption Standard), which protects your bank transactions, WhatsApp messages, and WiFi passwords. The famous One-Time Pad, the only mathematically unbreakable encryption, is just XOR with a truly random key as long as the message. XOR gates are also a fundamental building block in every computer processor.
▸ Visual: Encryption / Decryption Flow
▸ Concrete Example
Say the key byte is 0x55 (binary: 01010101). Let's encrypt "HELLO":
XOR with 0x55 = 01010101
Result = 00011101 = 29 → not a readable character
E = 69 = 01000101
XOR with 0x55 = 01010101
Result = 00010000 = 16 → also not readable
...encrypt all 5 letters → ciphertext: [29, 16, ...]
To decrypt, XOR the ciphertext bytes with the same key (0x55) again: 29 XOR 0x55 = 72 = H. Magic! The original text reappears.
💡 This is why XOR encryption is symmetric — encrypting twice with the same key gives you back the original. That's not true for other operations like AND or OR.
▸ How to Decode (Step by Step)
1. Get the ciphertext bytes and the key byte from the puzzle data
2. For each byte, XOR it with the key: plain_byte = cipher_byte ^ key
3. Convert each resulting number to a character (ASCII)
4. Join all characters → the decoded message!
plain = ''.join(chr(b ^ key) for b in ciphertext)
💡 If you don't know the key, try all 256 possible values (0–255). Only one will produce readable text. This brute-force is fast because there are only 256 keys to test.
▸ The XOR Truth Table
| A | B | A XOR B | Meaning |
|---|---|---|---|
| 0 | 0 | 0 | Same → off |
| 0 | 1 | 1 | Different → on |
| 1 | 0 | 1 | Different → on |
| 1 | 1 | 0 | Same → off |
▸ Real-World Applications
- AES encryption: The backbone of HTTPS, WiFi (WPA2), and encrypted messaging
- One-Time Pad: The only provably unbreakable encryption — just XOR with a random key
- Error detection: RAID storage arrays use XOR to recover data from failed drives
- CRC checksums: Network packets use XOR-based checksums to detect transmission errors