































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
































Number Theory ii
COLLABORATORS
TITLE :
Number Theory
ACTION NAME DATE SIGNATURE
WRITTEN BY Ben Lynn 1980-01-
REVISION HISTORY
NUMBER DATE DESCRIPTION NAME
What is the most natural way of doing arithmetic in Zn? Given two elements x, y ∈ Zn, we can add, subtract or multiply them as integers, and then the result will be congruent to one of the elements in Zn.
Example: 6 + 7 = 1 (mod 12), 3 × 20 = 10 (mod 50), 12 − 14 = 16 (mod 18).
These operations behave similarly to their mundane counterparts. However, there is no notion of size. Saying 0 < 4 (mod 8) is nonsense for example, because if we add 4 to both sides we find 4 < 0 (mod 8). The regular integers are visualized as lying on a number line, where integers to the left are smaller than integers on the right. Integers modulo n however are visualized as lying on a circle (e.g. think of a clock when working modulo 12).
Division is notably absent from the above discussion. If y divides x as integers, then one might guess we could use the usual definition. Let us see where this leads: we have 10 = 4 (mod 6). Dividing both sides by 2 gives the incorrect equation 5 = 2 (mod 6).
Thus we have to change what division means. Intuitively, division should "undo multiplication", that is to divide x by y means to find a number z such that y times z is x. The problem above is that there are different candidates for z: in Z 6 both 5 and 2 give 4 when multiplied by 2.
Which answer should we choose for "4/2", 5 or 2? We could introduce some arbitrary convention, such as choosing the smallest answer when considering the least residue as an integer, but then division will behave strangely.
Instead, we require uniqueness, that is x divided by y modulo n is only defined when there is a unique z ∈ Zn such that x = yz.
We can obtain a condition on y as follows. Suppose z 1 y = z 2 y (mod n). Then by definition, this means for some k we have y(z 1 − z 2 ) = kn. Let d be the greatest common divisor of n and y. Then n/d divides z 1 − z 2 since it cannot divide y, thus we have
z 1 y = z 2 y (mod n)
if and only if z 1 = z 2 (mod n/d).
Thus a unique z exists modulo n only if the greatest common divisor of y and n is 1.
We shall see that a unique z exists if and only if it is possible to find a w ∈ Zn such that yw = 1 (mod n). If such a w exists, it must be unique: suppose yw′^ is also 1. Then multiplying both sides of yw = yw′^ by w gives wyw = wyw′, which implies w = w′ since wy = 1. When it exists, we call this unique w the inverse of y and denote it by y−^1.
How do we know if y−^1 exists, and if it does, how do we find it? Since there are only n elements in Zn, we can multiply each element in turn by y and see if we get 1. If none of them work then we know y does not have an inverse. In some sense, modular arithmetic is easier than integer arithmetic because there are only finitely many elements, so to find a solution to a problem you can always try every possbility.
We now have a good definition for division: x divided by y is x multiplied by y−^1 if the inverse of y exists, otherwise the answer is undefined.
To avoid confusion with integer division, many authors avoid the / symbol completely in modulo arithmetic and if they need to divide x by y, they write xy−^1. Also some approaches to number theory start with inversion, and define division using inversion without discussing how it relates to integer division, which is another reason / is often avoided. We will follow convention, and reserve the / symbol for integer division.
Example: 2 × 3 + 4 ( 5 −^1 ) = 2 (mod 6).
Given three integers a, b, c, can you write c in the form
c = ax + by
for integers x and y? If so, is there more than one solution? Can you find them all? Before answering this, let us answer a seemingly unrelated question:
How do you find the greatest common divisor (gcd) of two integers a, b?
We denote the greatest common divisor of a and b by gcd(a, b), or sometimes even just (a, b). If (a, b) = 1 we say a and b are coprime.
The obvious answer is to list all the divisors a and b, and look for the greatest one they have in common. However, this requires a and b to be factorized, and no one knows how to do this efficiently.
A few simple observations lead to a far superior method: Euclid’s algorithm, or the Euclidean algorithm. First, if d divides a and d divides b, then d divides their difference, a - b, where a is the larger of the two. But this means we’ve shrunk the original problem: now we just need to find gcd(a, a − b). We repeat until we reach a trivial case.
Hence we can find gcd(a, b) by doing something that most people learn in primary school: division and remainder. We give an example and leave the proof of the general case to the reader.
Suppose we wish to compute gcd( 27 , 33 ). First, we divide the bigger one by the smaller one:
33 = 1 × 27 + 6
Thus gcd( 33 , 27 ) = gcd( 27 , 6 ). Repeating this trick:
27 = 4 × 6 + 3
and we see gcd( 27 , 6 ) = gcd( 6 , 3 ). Lastly, 6 = 2 × 3 + 0
Since 6 is a perfect multiple of 3, gcd( 6 , 3 ) = 3, and we have found that gcd( 33 , 27 ) = 3.
This algorithm does not require factorizing numbers, and is fast. We obtain a crude bound for the number of steps required by observing that if we divide a by b to get a = bq + r, and r > b/2, then in the next step we get a remainder r′^ ≤ b/2. Thus every two steps, the numbers shrink by at least one bit.
The above equations actually reveal more than the gcd of two numbers. We can use them to find integers m, n such that
3 = 33 m + 27 n
First rearrange all the equations so that the remainders are the subjects:
6 = 33 − 1 × 27
3 = 27 − 4 × 6
Then we start from the last equation, and substitute the next equation into it:
3 = 27 − 4 × ( 33 − 1 × 27 ) = (− 4 ) × 33 + 5 × 27 )
And we are done: m = − 4 , n = 5.
If there were more equations, we would repeat until we have used them all to find m and n.
Thus in general, given integers a and b, let d = gcd(a, b). Then we can find integer m and n such that
d = ma + nb
using the extended Euclidean algorithm.
Then the solutions for z, k are given by z = xr + tn, k = zs − ty
for all integers t. Thus z has a unique solution modulo n, and division makes sense for this case.
Also, r satisfies ry = 1 (mod n) so in fact y−^1 = r. Thus our claims are correct: we can divide x by y if and only if y has an inverse.
We can also see that y has an inverse if and only if gcd(y, n) = 1. (Actually, we have only proved some of these statements in one direction, but the other direction is easy.)
Note: even though we cannot always divide x by y modulo n, sometimes we still need to find all z such that yz = x.
We previously asked: given y ∈ Zn, does y−^1 exist, and if so, what is it?
Our answer before was that since Zn is finite, we can try every possibility. But if n is large, say a 256-bit number, this cannot be done even if we use the fastest computers available today.
A better way is to use what we just proved: y−^1 exists if and only if gcd(y, n) = 1 (which we can check using Euclid’s algorithm), and y−^1 can be computed efficiently using the extended Euclidean algorithm.
Example: does 7−^1 (mod 19) exist, and if so, what is it? Euclid’s algorithm gives
19 = 2 × 7 + 5
7 = 1 × 5 + 2 5 = 2 × 2 + 1
Thus an inverse exists since gcd( 7 , 19 ) = 1. To find the inverse we rearrange these equations so that the remainders are the subjects. Then starting from the third equation, and substituting in the second one gives
1 = 5 − 2 × 2 = 5 − 2 × ( 7 − 1 × 5 ) = (− 2 ) × 7 + 3 × 5
Now substituting in the first equation gives
1 = (− 2 ) × 7 + 3 × ( 19 − 2 × 7 ) = (− 8 ) × 7 + 3 × 19
from which we see that 7−^1 = − 8 = 11 (mod 19).
Suppose we wish to solve x = 2 (mod 5) x = 3 (mod 7)
for x. If we have a solution y, then y + 35 is also a solution. So we only need to look for solutions modulo 35. By brute force, we find the only solution is x = 17 (mod 35).
For any system of equations like this, the Chinese Remainder Theorem tells us there is always a unique solution up to a certain modulus, and describes how to find the solution efficiently.
Theorem: Let p, q be coprime. Then the system of equations
x = a (mod p)
x = b (mod q)
has a unique solution for x modulo pq.
The reverse direction is trivial: given x ∈ Zpq, we can reduce x modulo p and x modulo q to obtain two equations of the above form.
Proof: Let p 1 = p−^1 (mod q) and q 1 = q−^1 (mod p). These must exist since p, q are coprime. Then we claim that if y is an integer such that y = aqq 1 + bpp 1 (mod pq)
then y satisfies both equations:
Modulo p, we have y = aqq 1 = a (mod p) since qq 1 = 1 (mod p). Similarly y = b (mod q). Thus y is a solution for x.
It remains to show no other solutions exist modulo pq. If z = a (mod p) then z − y is a multiple of p. If z = b (mod q) as well, then z − y is also a multiple of q. Since p and q are coprime, this implies z − y is a multiple of pq, hence z = y (mod pq).
This theorem implies we can represent an element of Zpq by one element of Zp and one element of Zq, and vice versa. In other words, we have a bijection between Zpq and Zp × Zq.
Examples: We can write 17 ∈ Z 35 as ( 2 , 3 ) ∈ Z 5 × Z 7. We can write 1 ∈ Zpq as ( 1 , 1 ) ∈ Zp × Zq.
In fact, this correspondence goes further than a simple relabelling. Suppose x, y ∈ Zpq correspond to (a, b), (c, d) ∈ Zp × Zq respectively. Then a little thought shows x + y corresponds to (a + c, b + d), and similarly xy corresponds to (ac, bd).
A practical application: if we have many computations to perform on x ∈ Zpq (e.g. RSA signing and decryption), we can convert x to (a, b) ∈ Zp × Zq and do all the computations on a and b instead before converting back. This is often cheaper because for many algorithms, doubling the size of the input more than doubles the running time.
Example: To compute 17 × 17 (mod 35), we can compute ( 2 × 2 , 3 × 3 ) = ( 4 , 2 ) in Z 5 × Z 7 , and then apply the Chinese Remainder Theorem to find that ( 4 , 2 ) is 9 (mod 35).
Let us restate the Chinese Remainder Theorem in the form it is usually presented.
Theorem: Let m 1 , ..., mn be pairwise coprime (that is gcd(mi, m (^) j) = 1 whenever i ̸= j). Then the system of n equations
x = a 1 (mod m 1 )
... x = an (mod mn)
has a unique solution for x modulo M where M = m 1 ...mn.
Proof: This is an easy induction from the previous form of the theorem, or we can write down the solution directly.
Define bi = M/mi (the product of all the moduli except for mi) and b′ i = b− i 1 (mod mi). Then by a similar argument to before,
x =
n ∑ i= 1
aibib′ i (mod M)
is the unique solution.
An important consequence of the theorem is that when studying modular arithmetic in general, we can first study modular arithmetic a prime power and then appeal to the Chinese Remainder Theorem to generalize any results. For any integer n, we factorize n into primes n = pk 11 ...pk mm and then use the Chinese Remainder Theorem to get
Zn = Zpk 1 1
× ... × Zpkmm
To prove statements in Zpk , one starts from Zp, and inductively works up to Zpk. Thus the most important case to study is Zp.
Theorem: For an odd integer p > 1, let r = (p − 1 )/2. Then
(− 1 )r(r!)^2 = − 1 (mod p)
if and only if p is prime.
Proof: (p − 1 )! = 1 (p − 1 ) 2 (p − 2 )...((p − 1 )/ 2 )((p + 1 )/ 2 ) = 1 (− 1 ) 2 (− 2 )...r(−r) = (− 1 )r(r!)^2
and the result follows from Wilson’s Theorem.
If y ∈ Zn is invertible (that is, if y−^1 exists), then we say y is a unit. The set of units of Zn is denoted by Z∗ n, or Z× n.
We know y is a unit if and only if y and n are coprime. So the size of Z∗ n is precisely the number of integers in [ 1 ..n − 1 ] that are coprime to n.
We write φ (n) for the number of elements of Z∗ n. The function φ (n) is called the Euler totient function. Actually, it turns out to be convenient to have φ ( 1 ) = 1, so we prefer to define φ (n) as the number of integers in [ 1 ..n] coprime to n. (This agrees with our original definition except when n = 1.)
Examples: φ ( 6 ) = 2 since among [ 1 .. 6 ] only 1 and 5 are coprime to 6, and thus are the only units in Z 6.
Let p be a prime. Then every nonzero element a ∈ Zp is coprime to p (and hence a unit) thus we have φ (p) = p − 1.
How about powers of primes? If p is a prime, then the only numbers not coprime to pk^ are the multiples of p, and there are pk/p = pk−^1 of these. Hence φ (pk) = pk^ − pk−^1
Now let m, n be coprime, and let x ∈ Zmn. Let a = x (mod m) and b = x (mod n) (we reduce x modulo p and q). Then by the Chinese Remainder Theorem, x is a unit if and only if a and b are. Thus Z∗ pq = Z∗ p × Z∗ q.
Looking at the size of these sets gives this fact: for p, q coprime, we have
φ (pq) = φ (p)φ (q).
(Thus φ is multiplicative.)
Putting this together with the previous statement φ (pk) = pk^ − pk−^1 for prime p, we get that for any integer n = pk 11 ...pk mm (where we have factorized n into primes) we have
φ (n) = (pk 11 − pk 11 −^1 )...(pk mm − pk mm −^1 )
Often this formula is rewritten as
φ (n) = n
p 1
pm
Suppose we are asked to compute 3^5 modulo 7. We could calculate 3^5 = 243 and then reduce 243 mod 7, but a better way is to observe 3^4 = ( 32 )^2. Since 3^2 = 9 = 2 we have 3^4 = 22 = 4, and lastly
35 = 34 × 3 = 4 × 3 = 5 (mod 7).
The second way is better because the numbers involved are smaller.
This trick, known as repeated squaring, allows us to compute ak^ mod n using only O(log k) modular multiplications. (We can use the same trick when exponentiating integers, but then the multiplications are not modular multiplications, and each multiplication takes at least twice as long as the previous one.)
Let us examine the behaviour of the successive powers of 3 modulo 7.
31 = 3
32 = 2 33 = 6 34 = 4 35 = 5 36 = 1
Note we compute each power by multiplying the previous answer by 3 then reducing modulo 7. Beyond this, the sequence repeats itself (why?): 37 = 3 38 = 2
and so on.
At a glance, the sequence 3, 2 , 6 , 4 , 5 , 1 seems to have no order or structure whatsoever. In fact, although there are things we can say about this sequence (for example, members three elements apart add up to 7), it turns out that so little is known about the behaviour of this sequence that the following problem is difficult to solve efficiently:
(The discrete log problem) Let p be a prime, and g, h be two elements of Z∗ p. Suppose gx^ = h (mod p). Then what is x?
Example: One instance of the discrete log problem: find x so that 3x^ = 6 (mod 7). (Answer: x = 3. Strictly speaking, any x = 3 (mod 6) will work.)
Recall when we first encountered modular inversion we argued we could try every element in turn to find an inverse, but this was too slow to be used in practice. The same is true for discrete logs: we could try every possible power until we find it, but this is impractical.
Euclid’s algorithm gave us a fast way to compute inverses. However no fast algorithm for finding discrete logs is known. The best discrete log algorithms are faster than trying every element, but are not polynomial time.
Why don’t we bother studying the behaviour of nonunits under exponentiation?
First consider when n = pk^ for some prime p. Then a ∈ Zn is nonunit exactly when gcd(a, n) > 1, which in this case means a = d p for some d.
We have ak^ = dk^ pk^ = 0, thus in at most k steps we hit zero, which is uninteresting (at least for our purposes).
In general, write n = pk 11 ...pk nm. By the Chinese Remainder Theorem we have
Zn = Zpk 1 1
× ... × Zpkm m
Thus an element a ∈ Zn corresponds to some element (a 1 , ..., am) on the right-hand side, and a is a nonunit if at least one of the ai is a multiple of pi. From above, this means in at most ki steps, the ith member will reach zero, so in general, for some k, each aki is zero or a unit, hence we can restrict our study to units.
Note we have again followed an earlier suggestion: we handle the prime power case first and then generalize using the Chinese Remainder Theorem.
Let x be the order of a ∈ Z∗ n, and y be the order of b ∈ Z∗ n. What is the order of ab?
Suppose (ab)k^ = 1. Raising both sides to x shows
bkx^ = 1 kbkx^ = (ax)kbkx^ = (ab)kx^ = 1.
Since b has order y we see that y|kx.
Suppose x, y are coprime. Then we must have y|k. Similarly x|k, hence k must be a multiple of xy. On the other hand, we have (ab)xy^ = 1. Hence the order of ab is precisely xy: for elements with coprime orders, the order of their product is equal to the product of their orders.
More generally, let d = gcd(x, y). Then x|ky and y|kx implies that k must be a multiple of (x/d)(y/d). If z is the least common multiple of x and y, which we can compute by z = xy/d, then (ab)z^ = 1. All we can say at the moment is that the order of ab is a multiple of xy/d^2 and divides xy/d.
Suppose we are given positive integers e, N, and ae^ (mod N) for some unit a. How can we recover a?
One strategy is to find an integer d such that ade^ = a (mod N). By Euler’s Theorem, d will satisfy this equation if de = kφ (N)+ 1 for some k. In other words, we compute d = e−^1 (mod φ (N))
and compute (ae)d^ to recover a.
However it is not known how to compute φ (N) from N without factoring N, and it is not known how to factor large numbers efficiently.
Given an integer n, how can we tell if n is prime? Assume n is odd, since the even case is trivial.
The most obvious idea is to look for factors of n, but no efficient factoring algorithm is known.
By Fermat’s Theorem, if n is prime, then for any a we have an−^1 = 1 (mod n). This suggests the Fermat test for a prime: pick a random a ∈ [ 1 ..n − 1 ] then see if an−^1 = 1 (mod n). If not, then n must be composite.
However, equality may hold even when n is not prime. For example, take n = 561 = 3 × 11 × 17. By the Chinese Remainder Theorem Z 561 = Z 3 × Z 11 × Z 17
thus each a ∈ Z∗ 561 corresponds to some (x, y, z) ∈ Z∗ 3 × Z∗ 11 × Z∗ 17.
By Fermat’s Theorem, x^2 = 1, y^10 = 1, and z^16 = 1. Since 2, 10, and 16 all divide 560, this means (x, y, z)^560 = ( 1 , 1 , 1 ), in other words, a^560 = 1 for any a ∈ Z∗ 561.
Thus no matter what a we pick, 561 always passes the Fermat test despite being composite so long as a is coprime to n. Such numbers are called Carmichael numbers, and it turns out there are infinitely many of them.
If a is not coprime to n then the Fermat test fails, but in this case we can recover a factor of n by computing gcd(a, n).
We can do better by recalling n is prime if and only if the solutions of x^2 = 1 (mod n) are x = ±1.
So if n passes the Fermat test, that is, an−^1 = 1, then we also check a(n−^1 )/^2 = ±1, because a(n−^1 )/^2 is a square root of 1.
Unfortunately, numbers such as the third Carmichael number 1729 still fool this enhanced test. But what if we iterate? That is, so long as it’s possible, we continue halving the exponent until we reach a number besides 1. If it’s anything but −1 then n must be composite.
More formally, let 2s^ be the largest power of 2 dividing n − 1, that is, n − 1 = 2 sq for some odd number q. Each member of the sequence
an−^1 = a^2
sq , a^2
s− (^1) q , ..., aq.
is a square root of the preceding member.
Then if n is prime, this sequence begins with 1 and either every member is 1, or the first member of the sequence not equal to 1 is −1.
The Miller-Rabin test picks a random a ∈ Zn. If the above sequence does not begin with 1, or the first member of the sequence that is not 1 is also not −1 then n is not prime.
It turns out for any composite n, including Carmichael numbers, the probability n passes the Miller-Rabin test is at most 1/4. (On average it is significantly less.) Thus the probability n passes several runs decreases exponentially.
If n fails the Miller-Rabin test with a sequence starting with 1, then we have a nontrivial square root of 1 modulo n, and we can efficiently factor n. Thus Carmichael numbers are always easy to factor.
Exercise: What happens when we run the Miller-Rabin test on numbers of the form pq where p, q are large primes? Can we break RSA with it?
Given n, find s so that n − 1 = 2 sq for some odd q. Then we implement a single Miller-Rabin test as follows:
We also perform a few trial divisions by small primes before running the Miller-Rabin test several times.
Strictly speaking, these tests are compositeness tests since they do not prove the input is prime, but rather prove that an input is composite.
There exist deterministic polynomial-time algorithms for deciding primality (see Agrawal, Kayal and Saxena), though at present they are impractical.
A unit g ∈ Z∗ n is called a generator or primitive root of Z∗ n if for every a ∈ Z∗ n we have gk^ = a for some integer k. In other words, if we start with g, and keep multiplying by g eventually we see every element.
Example: 3 is a generator of Z∗ 4 since 3^1 = 3 , 32 = 1 are the units of Z∗ 4.
Example: 3 is a generator of Z∗ 7. From before the powers of 3 are 3, 2 , 6 , 4 , 5 , 1 which are the units of Z∗ 7.
Example: 3 is not a generator of Z∗ 11 since the powers of 3 (mod 11) are 3, 9 , 5 , 4 , 1 which is only half of Z∗ 11.
Theorem: Let p be a prime. Then Z∗ p contains exactly φ (p − 1 ) generators. In general, for every divisor d|p − 1, Z∗ p contains φ (d) elements of order d.
We prove Lagrange’s Theorem for Z∗ n. The proof can easily be modified to work for a general finite group.
Our proof of Euler’s Theorem has ideas in common with this proof.
Theorem: Let H be a subgroup of Z∗ n of size m. Then m|φ (n).
Proof: If H = Z∗ n then m = φ (n). Otherwise, let H = {h 1 , ..., hm}. let a be some element of Z∗ n not in H, and consider the set {h 1 a, ..., hma} which we denote by Ha. Every element in this set is distinct (since multiplying hia = h (^) ja by a−^1 implies hi = h (^) j), and furthermore no element of Ha lies in H (since hi = h (^) ja implies a = h− j 1 hi thus a ∈ H, a contradiction).
Thus if every element of Z∗ n lies in H or Ha then 2m = φ (n) and we are done. Otherwise take some element b in Z∗ n not in H or Ha. By a similar argument, we see that Hb = {h 1 b, ..., hmb} contains exactly m elements and has no elements in common with either H or Ha.
Thus iterating this procedure if necessary, we eventually have Z∗ n as the disjoint union of the sets H, Ha, Hb, ... where each set contains m elements. Thus m|φ (n).
Corollary: Euler’s Theorem (and Fermat’s Theorem). Any a ∈ Z∗ n generates a cyclic subgroup {a, a^2 , ..., ad^ = 1 } thus d|φ (n), and hence aφ^ (n)^ = 1.
Theorem: All subgroups of a cyclic group are cyclic. If G = ⟨g⟩ is a cyclic group of order n then for each divisor d of n there exists exactly one subgroup of order d and it can be generated by an/d^.
Proof: Given a divisor d, let e = n/d. Let g be a generator of G. Then ⟨ge⟩ = {ge, g^2 e, ..., gde^ = 1 } is a cyclic subgroup of G of size n/d.
Now let H = {a 1 , ..., ad− 1 , ad = 1 } be some subgroup of G. Then for each ai, we have ai = gk^ for some k. By Lagrange’s Theorem the order of ai must divide d, hence gkd^ = 1.
Since the order of g is n, we have kd = mn = mde for some m. Thus k = em and ai = (ge)m, that is each ai is some power of ge, hence H is one of the subgroups we previously described.
Theorem: Let G be cyclic group of order n. Then G contains exactly φ (n) generators.
Proof: Let g be a generator of G, so G = {g, ..., gn^ = 1 }. Then gk^ generates G if and only if gkm^ = g for some m, which happens when km = 1 (mod n), that is k must be a unit in Zn, thus there are φ (n) values of k for which gk^ is a generator.
Example: When Z∗ n is cyclic (i.e. when n = 2 , 4 , pk, 2 pk^ for odd primes p), Z∗ n contains φ (φ (n)) generators.
We can now prove a theorem often proved using multiplicative functions:
Theorem: For any positive integer n n = (^) ∑ d|n
φ (d).
Proof: Consider a cyclic group G of order n, hence G = {g, ..., gn^ = 1 }. Each element a ∈ G is contained in some cyclic subgroup. The theorem follows since there is exactly one subgroup H of order d for each divisor d of n and H has φ (d) generators.
In an abstract sense, for every positive integer n, there is only one cyclic group of order n, which we denote by Cn. This is because if g is a generator, then Cn = {g, g^2 , ..., gn^ = 1 } which completely determines the behaviour of Cn.
Example: Both Z∗ 3 and Z∗ 4 are cyclic of order 2, so they both behave exactly like C 2 (when considering multiplication only). This is an example of a group isomorphism.
Example: For n = 2 k^ pk 11 ...pk mm for odd primes pi, by the Chinese Remainder Theorem we have
Z∗ n = Z∗ 2 k × Z∗ pk 11 × ... × Z∗ pkm m
Recall each Z∗ pkii
is cyclic, and so are Z∗ 2 and Z∗ 4. Also recall for k > 2 we have that 3 ∈ Z∗ 2 k has order 2k−^2 and no element has a
higher order. Using some group theory this means the group structure of Z∗ n is
C 2 k− 1 ×C pk 11 −pk 11 −^1 × ... ×Cpkm m −pkm m−^1
when k = 1 , 2 and C 2 ×C 2 k− 2 ×Cpk 1 1 −p
k 1 − 1 1
× ... ×Cpkmm −pkm m− 1
when k > 2.
Let a ∈ Zn. We say a is a quadratic residue if there exists some x such that x^2 = a. Otherwise a is a quadratic nonresidue.
Efficiently distinguishing a quadratic residue from a nonresidue modulo N = pq for primes p, q is an open problem. This is exploited by several cryptosystems, such as Goldwassser-Micali encryption, or Cocks identity-based encryption. More general variants of this problem underlie other cryptosystems such as Paillier encryption.
Let p be an odd prime, as the case p = 2 is trivial. Let g be a generator of Z∗ p. Any a ∈ Z∗ p can be written as gk^ for some k ∈ [ 0 ..p − 2 ].
Say k is even. Write k = 2 m. Then (gm)^2 = a, so a is a quadratic residue. Exactly half of [ 0 ..p − 2 ] is even (since p is odd), hence at least half of the elements of Z∗ p are quadratic residues.
Suppose we have b^2 = a. Then (−b)^2 = a as well, and since b ̸= −b (since p > 2) every quadratic residue has at least two square roots (in fact, we know from studying polynomials there can be at most two), thus at most half the elements of Z∗ p are quadratic residues. (Otherwise there are more square roots than elements!)
Thus exactly half of Z∗ p are quadratic residues, and they are the even powers of g.
Given a = gk, consider the effect of exponentiating by (p − 1 )/2. If k is odd, say k = 2 m + 1, we get
a(p−^1 )/^2 = g(^2 m+^1 )(p−^1 )/^2 = g(p−^1 )mg(p−^1 )/^2 = g(p−^1 )/^2
The square of g(p−^1 )/^2 is gp−^1 = 1, so g(p−^1 )/^2 is 1 or −1. But g has order p−1 (g is a generator) thus we must have g(p−^1 )/^2 = −1.
If k is even, say k = 2 m, then a(p−^1 )/^2 = g(p−^1 )m^ = 1.
In other words, we have proved Euler’s Criterion, which states a is a quadratic residue if and only if a(p−^1 )/^2 = 1, and a is a quadratic nonresidue if and only if a(p−^1 )/^2 = −1.
Example: We have −1 is a quadratic residue in Zp if and only if p = 1 (mod 4).
We define the Legendre symbol for odd primes p and integers a by a p
= a(p−^1 )/^2.
The symbol can also be written as (a|p).
Thus:
a p
= 1 if a is a quadratic residue of p