random-variable
The Problem
Three random variables: (message), (key), (ciphertext). I know the distributions of and individually. How do I find the distribution of ?
More generally: when a new random variable is defined as a function of others (), how do I compute its PMF?
Where I Got Stuck
I could reason about using Venn diagrams and set operations. But random variables are different. When someone writes and asks for , the answer depends on how and relate to each other. I didn't have a systematic way to go from "I know and " to "here's ."
The event notation doesn't give you a way to do arithmetic on probabilities. You can intersect events, union them, complement them. But you can't XOR two events or add them. Random variables let you do that because they're functions, not sets.
Random Variables Are Functions
A random variable is a deterministic function from the sample space to real numbers:
is shorthand for the probability of the event , the inverse image of under .
Because RVs are functions, we can compose them. for every outcome . That's what "" means. The new variable is just another function on the same sample space, defined pointwise.
The Joint Table Is the Workspace
With two RVs and , stop listing sample space outcomes. Build the joint PMF:
For fair independent coins ():
| 0 | 1 | |
|---|---|---|
| 0 | ||
| 1 |
If : each cell is .
This table is the object you work with. Everything else follows from it.
Marginalization: = sum of row . You project the 2D table onto one axis.
Conditioning: = take row , divide each cell by the row sum. Same "shrink the universe" idea from conditional-probability, applied to the table instead of Venn diagrams.
Deriving a New Distribution
To find where : look at every cell in the joint table, check whether , and sum those probabilities.
For our fair coins: comes from cells where , which are and . So .
The same technique works for any operation. For addition () with independent RVs, fixing forces , giving the convolution formula:
If and are dependent, replace with .
That's the general technique: enumerate all input pairs that produce the target output, sum their joint probabilities.
XOR vs Addition: Why the Outputs Look Different
The operation you apply determines the shape of the resulting distribution.
XOR is a permutation. Fix any row in the joint table. As ranges over , the output hits every value exactly once. Every row is a permutation of the output space. If is uniform, each output value gets equal total weight.
Addition piles up in the middle. Multiple input pairs can produce the same sum. Middle values have more combinations () while edge values have fewer (). Mass accumulates in the center.
| XOR () | Addition () | |
|---|---|---|
| Per-row structure | Permutation (each output once) | Multiple pairs per output |
| Uniform Uniform | Uniform | Triangle (peaked) |
| Anything Uniform | Uniform | Still peaked |
Adding more independent uniform variables keeps smoothing the peak toward a bell curve (Central Limit Theorem).
The Row-Universe Analysis
This is the part that connects to the one-time pad. Split the joint table by rows of . Each row is a separate universe conditioned on a specific key value.
- Row : . The ciphertext copies the message.
- Row : . The ciphertext flips the message.
For to be independent of , the distribution of must look the same in every row:
The left side is . The right side is . These are equal only when , so must be uniform.
This is the one-time pad property: Any bias Uniform Uniform. Even if is 90% zeros, a uniform washes it away completely:
The factors out of the sum, and the remaining .
See otp-security-proof for how this drives the full security argument.
Independence Matters, Not Just Uniformity
being uniform isn't enough. must also be independent of .
Counterexample: let (perfect dependence). is still uniform since is fair. But always. The ciphertext is a constant. It leaks everything about (namely, that ).
The proof above used without conditioning on . That step requires . Without independence, you'd need , and you can't conclude uniformity.