# Why must we use XOR?

Does it really matter if we used AND, OR or XOR with the one-time pad?** The answer is yes**, and it’s extremely important to understand why. Recall from the previous article that** AND** has a __75%__ of outputting 0 and a __25%__ chance of outputting a 1. While **OR** has a __25%__ chance of outputting 0 and __75%__ chance of outputting 1. While the** XOR** operation has a **50% chance of outputting 0 or 1**.

Let’s look at a visual example to see the different scrambling effects of AND vs. OR vs. XOR by **encrypting an image**. Here is a digital image of Charles Babbage:

It contains thousands of tiny colored squares called pixels. Each pixel in this image can be represented as a 24 bit sequence as shown in the previous article. Let's call this our **plaintext image (or message).**

First let’s see what happens when we **AND** each bit in the image file with a stream of **random bits.**

# AND

Notice most of the original message shines through. This happens anytime a random shift of 1 is applied, or when the plaintext is 0:

Next let’s see what happens when we **OR** each bit in the image file with a stream of **random bits.**

# OR

Notice most of the original message shines through. This happens anytime a random shift of 0 is applied, or when the plaintext is 1**:**

Finally, let’s see what happens when we **XOR** each bit in the image file with a stream of **random bits. **

(drum roll please...)

# XOR

**Where did Charles go?**

Notice that the plaintext only shines through **50% of the time**, which results in __noise__ as each pixel is **equally likely to be 0 or 1**.

This image contains __no information__ about the original image. If we didn’t provide the shift sequence it would be **impossible** for you to reverse it back to the original image. You could try every possible sequence, but that would result in every possible image! How could you know it was Babbage? It's equally likely to be a picture of you** or anything else you can think of. **

Isn’t that interesting? Makes me smile everytime I see it!

Next, let’s practice the XOR, OR and AND operators and __discover some more interesting properties__ while doing so....

image credit

## Share a tip

When naming a variable, it is okay to use most letters, but some are reserved, like 'e', which represents the value 2.7831...## Thank the author

This is great, I finally understand quadratic functions!## Have something that's not a tip or thanks about this content?

## This discussion area is not meant for answering homework questions.