Math Review
A.1. Strings
denotes the set of -bit binary strings. denotes the length of the string , usually measured in bits.
When it is clear from context that we are talking about strings, means “the string of 's,” not the integer 0 to the th power. Similarly, refers to the string of 's.
When and are strings of the same length, denotes the bitwise exclusive-or (xor) of the two strings.
For example, . The following algebraic facts about the xor operation are frequently useful:
There are two ways to think about xor that can be helpful in different situations:
-
As bit-flipping: xor'ing a bit with has no effect; xor'ing with flips that bit. You can think of as: “starting with , flip the bits at all the positions where has a .”
-
As addition mod 2: xor is just addition mod 2 in every position. This interpretation of xor helps to justify its algebraic properties, like the fact that it is commutative and associative. Also, is congruent to 0 mod 2, which explains why .
We write the result of concatenating two strings and as .
A.2. Probability
A (discrete) probability distribution over a set of outcomes is written as a function that associates each outcome with a probability . We often say that the distribution assigns probability to outcome . For each outcome , the probability distribution must satisfy the condition . The sum of all probabilities must also equal 1.
The uniform distribution over a finite set assigns probability to every .
The notation is defined over individual outcomes, but we also extend it to apply to events, which are just collections of many outcomes. For example, when I roll a six-sided die, the event “I rolled an even number” corresponds to the events 2, 4, and 6. Formally, an event defines a subset of outcomes, and its probability is defined to be .
A six-sided die has faces numbered . When rolling such a die (at least in a math problem) the outcome is uniformly distributed. Thus,
If and are events, then we write to denote the event that happens and happens. If and are independent events, then .
Upper Bounds
We often use probabilities to describe a certain “bad event” that violates security. In these cases, it is enough to show just an upper bound on the probability.
If and are events, then we write to denote the event that happens or happens (or both). The union bound states that:
The sum is an upper bound because it might double-count the probability that both and happen. Importantly, events and don't have to be independent for the union bound to apply. We most commonly see the union bound show up in the following way:
Suppose I toss a 100-sided die, ten times, and consider the probability that I observed a in any of those rolls. We can use the union bound to derive a simple upper bound on the probability:
More generally:
If some event has probability , then after attempts, the probability of observing the event in any of the trials is at most .
Strategies For Probability
If is an event, then we write to refer to the event that doesn't happen. The two probabilities and satisfy the following relationship:
Often one of and is much easier to reason about.
I roll a six-sided die, six times. What is the probability that I see some outcome more than once? Let's think about all the ways this could happen. Well, two of the rolls could be 1, or three of rolls could be 1, or all of them could be 1, two of them could be 1 and the rest could be 2, and so on. Wait, am I double-counting repeated 2s and repeated 1s?
An easier way to attack the problem is to focus on the complementary event, that all 6 rolls are distinct. The probability we care about is . All rolls are distinct if the sequence of dice rolls spell out a permutation of . There are such permutations, out of total possible outcomes. Hence, the answer to the question is
Another trick is to change the relative order of independent sampling events. If two values are sampled independently, then it makes no difference whether they are sampled simultaneously or sequentially, in either order. It can often be helpful to imagine that they are sampled sequentially, and to reason about probabilities from the perspective of an intermediate moment in time, after one value has been chosen/fixed but the other has not.
When rolling two six-sided dice, what is the probability that the dice match? Here is a standard (and totally correct way) to answer the question:
When rolling two six-sided dice, there are total outcomes (a pair of numbers), and each one has probability under a uniform distribution. There are six outcomes in which the dice match: both dice 1, both dice 2, both dice 3, and so on. Therefore, the probability of rolling matching dice is .
A different way to arrive at the answer goes like this:
Imagine I roll the dice sequentially, and I pause after rolling the first die but before rolling the second. The result of the first die has been fixed; let's call that value . The two dice will match only if another is rolled on the second die. Rolling this specific value of on the second die (indeed, rolling any particular value) happens with probability .
Linguistic Precision
Being “random” is not a property of a specific outcome, it is a property of the process that generates the outcome. It therefore doesn't make much sense to refer to a “random string.” Is 42 a random number? Is “heads” a random coin?
I try to use precise language in this book and avoid describing values as “random.” However, every cryptographer I know (yes, even your dear author) says things like “ is a random string” all the time to mean “ was chosen uniformly.” It's not a terrible sin to speak in this way, just keep in mind that this is merely a (lazy?) shortcut for a more precise meaning.
A.3. Modular arithmetic
When and are integers, we say that divides (equivalently, is a factor of , and is a multiple of ), and write , if there exists an integer such that . When does not divide , we write .
This definition applies to both positive and negative numbers (and to zero).
Let and be integers, with positive. Then (pronounced “ mod ”) denotes the remainder after dividing by . More formally, is the unique value such that .
Pay special attention to the fact that is always a nonnegative number, even if is negative. A good way to remember how this works is:
is more than a multiple of .
Not “closer to zero than” but “more than” a multiple of .
In the third example, is 1 more than , which is a multiple of 7. In the fourth example, is 6 more than , which is a multiple of 7.
Unfortunately, some programming languages define for negative numbers as , so they would define to be . This is clearly absurd, and it's about time we stood up to these programming language designers and smashed them over the head with some mathematical truth! For now, if you are experimenting using a programming language, be sure to check whether it defines in the correct way.
For positive , we write to denote the set of integers modulo . These are the possible remainders that result when you divide by
For positive , we say that integers and are congruent modulo , and write , if . An alternative definition is that if and only if
It's important to appreciate the (subtle) distinction between and :
is true, because divides . Neither side of the equation (congruence) are from the set , and that's fine.
is false. The right-hand side evaluates to the integer . The equals-sign compares equality as integers; and are different integers.
Expressions like make sense for any (including negative!), but expressions like make sense only if
In other resources you might see the notation “” instead of “.” I dislike this notation because “” is easily mistaken for an operation or action that affects only the right-hand side of the equation. In reality, it modifies the entire expression . Even though subscripts on the symbol look weird at first, I think it's worth it.
If and , then is a common divisor of and . The largest possible such is called the greatest common divisor (GCD), denoted . If , then we say that and are relatively prime.
The recursive algorithm that we still use today to compute GCDs was first described by Euclid around 300bce. It is widely regarded as the first numerical algorithm:
Strategies For Modular Arithmetic:
You may often need to compute a value like:The straightforward way to evaluate this expression is to first compute the value of the complicated expression over the integers, then reduce the answer mod . You'll get the correct answer this way, but there's often a better choice.
If you need to know the final result mod , then you can/should simplify intermediate values mod as you go. You'll get the same answer, but usually with less effort.
Consider the expression:
The unsophisticated way of computing this value is:
Those of us who don't want to compute in our heads can reduce the intermediate results mod 11 as we go:
“Simplify” doesn't always mean “reduce mod ,” resulting in a number from . It means to replace one value with a congruent value that is easier to work with. Often a negative number is more favorable than a positive one:
Here's another way to evaluate the expression from the previous example:
I can compute in my head, by noticing that . Therefore:
I can quickly compute in my head, although I have not memorized the integer . I simply notice that and compute this way:
A.4. Exponents and logarithms
You probably learned (and then forgot) these identities in middle school or high school:
Never ever ever write . If you do, your cryptography instructor will realize that life is too short, immediately resign from teaching, and join a traveling circus. But not before changing your grade in the course to a zero. Harsh, maybe, but fair.
A.5. Big-
Big- notation describes the “shape” of a function as it approaches infinity.
A function is in the set if there exists and such that for all we have . In other words, eventually (after ) overtakes .
is because:
so the definition of is satisfied with and .
We could have also written:
so the definition of is satisfied with and .
A.6. Linear algebra
A matrix is a 2-dimensional grid of scalar values. An matrix has rows and columns. The example below is a matrix:
A vector is, according to our conventions, a matrix with one column. If and , then their inner product, written , is defined to be:
If is an matrix and is a matrix, then their product is an matrix, and its value at row and column is the inner product of the -th row of with the -th column of .
The transpose of a matrix , written as , is what results by reflecting it across its main diagonal. For example:
The transpose of an matrix is an matrix. The transpose operation satisfies the following important properties:
Exercises
-
Carefully use the algebraic properties of xor to derive the following useful fact, for strings :
In other words, if you know any two of the values in the equation “”, then you can solve for the third.
-
What is the result of xor'ing every -bit string? For example, the expression below is the xor of every 5-bit string:
Give a convincing justification for your answer.
-
Compute the exact probability described in example A.2.6.
-
Consider rolling several -sided dice, where the sides are labeled .
-
When rolling two of these dice, what is the probability of rolling a pair of 1s?
-
When rolling two of these dice, what is the probability that they don't match?
-
When rolling three of these dice, what is the probability that they all match?
-
When rolling three of these dice, what is the probability that they don't all match (including the case where two match)?
-
When rolling three of these dice, what is the probability that at least two of them match (including the case where all three match)?
-
When rolling three of these dice, what is the probability of seeing at least one 1?
-
-
h What is ? The answer might depend on whether is even or odd.
Rearrange the terms of the sum so that you get many values that are “favorable” mod .
-
What is ?
-
Without using a calculator, what are the last two digits of ? Start by translating “what are the last two digits” into a question about modular arithmetic.
-
Without using a calculator, what is ? That's not me being excited about the number one thousand, it's one thousand factorial!
-
Which values satisfy ? Which satisfy ?
Over the integers, . How is this fact reflected when working mod 11?
-
Rewrite each of these expressions as something of the form .
-
Chapter Notes
It is possible to give sense to statements like “ is a random string” using the methodology of Kolmogorov complexity. See [146] for a comprehensive reference.
Euclid described the GCD algorithm in Book 7 of his famous Elements. He was likely not the first to discover the algorithm.