XOR Operation

What is XOR?

XOR stands for exclusive or.

It compares two bits and asks: are they different?

Different → 1. Same → 0.


The Rule

AABBABA \oplus B
000
011
101
110

Two 0s? Same → 0

Two 1s? Same → 0

One of each? Different → 1


XOR with Binary Numbers

To XOR two binary numbers, compare each column:


Key Properties

1. Anything XOR itself is 0

AA=0A \oplus A = 0

Same bits cancel out.


2. Anything XOR 0 is itself

A0=AA \oplus 0 = A

XOR with 0 changes nothing.


3. XOR twice cancels out

ABB=AA \oplus B \oplus B = A

This is the magic property.


Why Cryptography Loves XOR

That third property makes XOR perfect for encryption.

  • Take a message
  • XOR it with a key → get ciphertext
  • XOR ciphertext with the same key → get message back

Same operation encrypts and decrypts.