Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Math 152: Intro to Mathematical Software
2017-03-10
Kiran Kedlaya; University of California, San Diego
adapted from lectures by William Stein, University of Washington
Lecture 25: Algebra and number theory (prep for cryptography): part 2
Announcements:
Guest lectures next week:
Monday, March 13: Kartik Venkatram
Wednesday, March 15: Alina Bucur
No sections on Monday, March 13.
Office hours next week:
Zonglin: Thursday, March 16, 3:30-5:30 in APM 5748.
Me: Friday, March 17, 11-12 in APM 7202.
Peter: Friday, March 17, 12-1 and 3-4 in APM 6132.
Next week's homework due Friday, March 17 at 8pm. Peer grading due Sunday, March 19 at 8pm.
The first half of this assignment is "normal" (number theory and cryptography).
The second half is freeform: create your own lecture! See the assignment for details.
Please do your course evaluation (CAPE)! Evaluations close Monday, March 20 at 8am.
HW1-6 grades are available on TritonEd, plus some attendance and peer grading scores. Remember, there is no final exam for this course.
Regarding grade cutoffs: as a minimum, 90% will be at least an A-, 80% at least a B-, 70% at least a C-. However, I will lower the cutoffs if necessary to achieve a distribution comparable to other upper-division courses (e.g., under no circumstances will the A range include fewer than 20% of the class).
This might be useful: https://wiki.sagemath.org/quickref?action=AttachFile&do=get&target=quickref-nt.pdf
Back to the Chinese remainder theorem
Last time, I demonstrated how to use the extended Euclidean algorithm to make the Chinese remainder theorem explicit. What was that function called again?
e to the pi Minus pi
There is also a built-in command for this!
Multiplicative order and primitive roots
Let be integers with . Using the extended Euclidean algorithm as above, one can find a multiplicative inverse of modulo , i.e., a value such that . In fact, Sage will do this automatically.
As a consequence of the existence of the multiplicative inverse, there always exists a positive integer such that . (There must be two powers that coincide mod , and we can cancel the powers of from one side.)
If is prime, the little Fermat theorem implies that always works (although it need not be the smallest such value; more on this in a moment). For general , there is a generalization of the Fermat theorem due to Euler: we have where denotes the Euler phi function (or totient function): if has prime factorization , then [ \phi(n) = (p_1 - 1)p_1^{e_1-1}(p_2-1)p_2^{e_2-1} \cdots. ] For those who know group theory: recall that this works because the residue classes mod which have no common factor with form a group under multiplication, and is its order.
So now it makes sense to consider the smallest positive integer such that . This integer must divide , otherwise the remainder of mod would be an even smaller value. (Or use group theory!) This is called the multiplicative order of mod .
Important result: if is prime, then there is always at least one value of for which the multiplicative order of mod is equal to the maximum possible value . Any such is called a primitive root mod ; these are relevant for discrete logarithms, more on which later.
(Abstract algebra interpretation; if is prime, then is a cyclic group!)
Discrete logarithms
Let be a prime. Suppose that is a primitive root mod . Then for any not divisible by , the discrete logarithm of mod , with respect to the base , is the integer such that .
This looks straightforward enough, but it is actually very difficult to compute discrete logarithms! There is no obvious trick for this.
As a result, the function is often treated as a one-way function: it is easy to compute but hard to invert. (This is a practical definition, not a formal mathematical one, because we (probably) cannot say for sure that it is actually hard to compute, as opposed to our merely being ignorant.)
In any case, the existence of one-way functions makes it feasible to have public-key cryptography, where everyone knows how to encrypt a message but only one person knows how to decrypt; or public-key signature schemes, where only one person knows to encrypt but everyone knows how to decrypt.
The difficulty of integer factorization behaves in a similar (but slightly more complicated) way: if are two prime numbers, then it is easy to form the product but much harder to recover and from the product.
Quadratic residues
For a positive integer, an integer is a quadratic residue mod if there exists a perfect square congruent to modulo .
For example, say . To test whether a perfect square is congruent to modulo , we need only test . Their residues modulo are .
For an odd prime, the list of quadratic residues mod will include 0 plus other values. (If we run over , no residue can occur more than twice: if , then is divisible by , and so one of or must be.)
For an odd prime and not divisible by , is a quadratic residue modulo if and only if its discrete logarithm (with respect to any base) is even.
The Legendre symbol is defined to be if , if is a nonzero quadratic residue modulo , and if is not a quadratic residue mod . This symbol has the multiplicativity property: [ \left( \frac{a}{p} \right) \left( \frac{b}{p} \right) = \left( \frac{ab}{p} \right). ] (The less-than-obvious part is that the product of two quadratic nonresidues is a quadratic residue. This would fail if were not prime.)
The law of quadratic reprocity (originally proved by Gauss) states that if are distinct odd primes, then [ \left( \frac{p}{q} \right) \left( \frac{q}{p} \right) = (-1)^{(p-1)(q-1)/4}. ] That is, the two Legendre symbols agree if either or is congruent to 1 mod 4, and disagree if they are both congruent to 3 mod 4.
If is not prime, you can apply quadratic reciprocity by first factoring . But this is not necessary: if one defines the Kronecker symbol to extend the Legendre symbol via the rule [ \left( \frac{a}{b_1} \right) \left( \frac{a}{b_2} \right) = \left( \frac{a}{b_2} \right), ] then the formula [ \left( \frac{p}{q} \right) \left( \frac{q}{p} \right) = (-1)^{(p-1)(q-1)/4}. ] extends to all odd positive integers .
This still leaves the prime 2, but there is another formula of Gauss to handle this case: [ \left( \frac{2}{p} \right) = (-1)^{(p-1)/8}. ] That is, if is an odd prime, then 2 is a quadratic residue mod if is congruent to 1 or 7 mod 8, and a quadratic nonresidue mod if is congruent to 3 or 5 mod 8.
Upshot: you can compute Legendre (and Kronecker) symbols quickly using a form of the Euclidean algorithm!