Cryptography Hub Rolling Thunder Security · Cybersecurity Fundamentals

Module · Foundational Mathematics

XOR Exclusive OR

A single-bit operation that quietly powers every stream cipher, every one-time pad, and the inner machinery of every block cipher you will ever use. Learn it once and it never leaves you.

The Rule, In One Sentence

One OR the other, but not both.

XOR is short for Exclusive OR. It returns true (1) when exactly one of its two inputs is true, and false (0) when the inputs match. The symbol is , a circle with a plus inside, and it is the most important operator in symmetric cryptography.

Distinction

OR is generous. XOR is strict.

The two operations agree on three out of four cases. Their disagreement is what gives XOR its name and its cryptographic power.

Inclusive OR

Symbol: · "either, or both"

00=0
01=1
10=1
11=1

Coffee OR tea? Both is fine.

Exclusive OR

Symbol: · "one or other, not both"

00=0
01=1
10=1
11=0

Window XOR aisle seat. Pick one.

Truth Table

The Whole Operation, On One Grid

Read the table by picking your first bit from the left column, your second bit from the top row, and finding where they meet. Click any cell to read what it means. Cells where the bits match return 0. Cells where they differ return 1.

0
1
0
1
Click any of the four result cells above to see what the bits mean.
0 0 = 0
0 1 = 1
1 0 = 1
1 1 = 0

Try It

Flip the Bits Yourself

Click either bit to toggle it between 0 and 1. The result panel updates instantly. Notice how the result is 1 only when the two bits are different.

Bit A
Bit B
0
A ⊕ B

Tip: press A or B on your keyboard to toggle each bit.

From Bits To Bytes

XOR a Whole Byte at a Time

Real data is not a single bit. It is bytes, kilobytes, gigabytes. To XOR a byte, simply XOR each pair of bits in the same column. Stack the values, line them up, and apply the truth table eight times.

Plaintext
char: A dec: 65 hex: 41
Key
char: K dec: 75 hex: 4B
⊕  XOR EACH COLUMN  ⊕
Ciphertext
char: · dec: 10 hex: 0A
⊕  XOR WITH KEY AGAIN  ⊕
Recovered
char: A dec: 65 hex: 41

The Cryptographic Magic

Why XOR is the Heart of Symmetric Encryption

XOR has a quiet superpower: applying the same key twice gives you back the original message. The encryption operation and the decryption operation are literally the same operation. No inverse function needed.

1

Start with plaintext and a key

You have a message you want to hide (the plaintext) and a secret value known only to sender and receiver (the key). Both are sequences of bits.

P = the message bit · K = the key bit
2

XOR them to encrypt

The sender XORs each plaintext bit with the matching key bit. The result is the ciphertext, which looks like random noise to anyone without the key.

PK = C
3

XOR again to decrypt

The receiver applies XOR with the same key. Because XOR is self-inverse, the key cancels itself out and the original plaintext appears.

CK = (PK) ⊕ K = P
4

The same operation runs both directions

This is why ChaCha20, RC4, AES-CTR, and the one-time pad all share the same final step: XOR the data with a keystream. Encryption and decryption are the identical operation. The only thing that has to be secret is the key.

Reference

Properties Worth Memorizing

These four identities show up in cryptanalysis, hash construction, parity checking, and almost every cipher proof you will read. Keep them close.

Identity

A ⊕ 0 = A

XOR with zero leaves the value unchanged. Zero is the do-nothing key.

Self-Inverse

A ⊕ A = 0

XOR a value with itself and you always get zero. This is what makes the "decrypt by re-encrypting" trick work.

Commutative

A ⊕ B = B ⊕ A

The order of operands does not matter. Useful when reordering equations during analysis.

Associative

(A ⊕ B) ⊕ C = A ⊕ (B ⊕ C)

Grouping does not matter either. You can XOR a stream of values in any order and get the same final result.