Crypto 0 to hero - Episode 03 - XOR > Why do cryptographers always...

@mattpiz
Matthieu Pizenberg@mattpiz
27 views Jun 26, 2024 ~2 min read
Advertisement
1
Crypto 0 to hero - Episode 03 - XOR

> Why do cryptographers always end up alone?
> Because they keep xor-ing their partners.

Did you get it? Don’t worry it’s not that good. 1/m
2
So there is this logic operator called XOR ("eXclusive OR") that cryptographers love and use all over the place. Given two boolean variables, that we will represent in binary (0 or 1), the XOR operator, noted ⊕, is defined as follows. 2/m
Media image
3
It’s a simple operator, especially with computers that can perform it extremely fast. And it has one fundamental property for cryptography. 3/m
4
Given a random variable Y over {0,1}^n with an unknown distribution, and another random variable X which is uniform on {0,1}^n and independent of Y, then Z defined by Z := Y ⊕ X is also uniform on {0,1}^n. 4/m
5
In plain English, if you XOR whatever with something that looks random, the result also looks random. This is useful because then we can XOR useful data (like plaintext) with random data and the result will look random. Let’s detail a bit more precisely the previous property. 5/m
6
The set defined by "{0,1}^n" contains all possible data of size "n" bits, where each bit is either 0 or 1. So "00", "01", "10" and "11" are all members of {0,1}^2. 6/m
7
Saying Y is a random variable in that set with an unknown distribution means we don’t know how likely each value is. Maybe Y will only produce "00", or maybe "10" is more likely and the rest are equally likely. 7/m
8
Saying X is uniform on {0,1}^n means that all 2^n possible values are equally likely. So the probability of every value is Pr\[x] = 1 / 2^n. 8/m
9
Saying that X is independent from Y means that knowing what Y will be gives no clue as to what X will be. It’s the opposite of saying X and Y are correlated. For example, if X is always the number following Y, knowing that Y is "00" implies we know that X will be "01". 9/m
10
But since X and Y are independent, we have no clue about what X might be. Mathematically, it means that for any pair of values (a, b), the probability of the combination is the product of each probability.
Pr[X=a and Y=b] = Pr[X=a] * Pr[Y=b]. 10/m
11
Let’s prove the XOR property for with n=1. X and Y can both be 0 or 1, we don’t know Y distribution so we note P0 and P1 its probabilities of being 0 or 1. Since X is uniform, both 0 and 1 have probability of 1/2. Z is defined as Y ⊕ X. 11/m
Media image
12
That’s it, Pr[Z=0] = Pr[Z=1] = 1/2. So Z is uniform, whatever the distribution of Y!

That’s all for today! I hope you liked it. See you in the next episode! 12/12
Actions
What You Can Do
  • Export as PDF or Markdown
  • Batch Export to Notion
  • Bookmark & Highlight
  • Screenshot Tweet
Create Free Account

Includes 7-day Premium trial

Advertisement