Professional Documents
Culture Documents
Review Questions
1. A positive integer is a prime if and only if it is exactly divisible by two integers, 1
and itself. A composite is a positive integer with more than two divisors.
3.
a. The function π(n) finds the number of primes smaller than or equal to n.
b. Euler’s phi-function, φ(n), which is sometimes called the Euler’s totient func-
tion, finds the number of integers that are both smaller than n and relatively
prime to n.
5. We discussed two versions of Fermat’s little theorem. The first version says that if
p is a prime and a is an integer such that p does not divide a, then we have ap−1 ≡
1(mod p). The second Version removes the condition on a. It says that if p is a
prime and a is an integer, then ap ≡ a (mod p). Two immediate applications of this
theorem is to find solutions to exponentiation and multiplicative inverses when the
modulus is a prime.
7.
a. Mersenne defined the formula Mp = 2p − 1 that was supposed to enumerate all
primes. However, not all Mersenne numbers are primes.
b. Fermat defined the formula Fn = 22n + 1 that was supposed to enumerate all
primes. However, not all Fermat’s numbers are primes.
9. We mentioned the trial-division, Fermat, Polard p − 1, Polard rho, quadratic sieve,
and number field sieve.
11. A quadratic congruence is an equations of the form a2x2 + a1x + a0 ≡ 0 (mod n). In
this text, we have limited our discussion to equations of the form x2 ≡ a (mod n).
In this equation a is called a quadratic residue (QR) if the equation has two solu-
tions; a is called quadratic nonresidue (QNR) if the equation has no solutions.
1
2
Exercises
13.
a. The number of primes between 100,000 and 200,000 can be found as
π(200,000) − π(100,000). Using the upper and lower limits devised by Gauss
and Lagrange, we have
16385 < π(200,000) < 17985 → π(200,000) ≈ 17200
8688 < π(100,000) < 9587 → π(100,000) ≈ 9138
π(200,000) − π(100,000) ≈ 17200 − 9138 ≈ 8062
b.
(1518 mod 17) = [(15 mod 17) × (1517 mod 17)] mod 17
= [(−2 mod 17) × (−2 mod 17)] mod 17 = 4 mod 17
c.
3
d.
(145102 mod 101) = [(145101 mod 101) × (145 mod 101)] mod 101
= [145 ×145] mod 101 = [44 × 44] mod 101 = 17 mod 101
b.
16−1 mod 323 = 16φ(323) −1 mod 323 = 16287 mod 323 = 101 mod 323
c.
20−1 mod 403 = 20φ(403) −1 mod 403 = 20359 mod 403 = 262 mod 403
d.
44−1 mod 667 = 44φ(667) −1 mod 667 = 44615 mod 667 = 379 mod 667
25. It can be checked that if 2n − 1 is a prime, then n is a prime. However, there are
some values of n for which 2n − 1 is a composite, but n is a prime (n = 11, for
example). In other words, if n is a prime, 2n − 1 may or may not be a prime; if 2n −
1 is a prime, then n is a prime. This is to say that not all Mersenne numbers are
primes. Since Mersenne’s idea cannot be used for primality test, the fact stated in
this problem cannot be used for primality test.
22 − 1 = 3 is a prime → n = 2 is a prime
23 − 1 = 7 is a prime → n = 3 is a prime
24 − 1 = 15 = 3 × 5 is a composite → n = 4 is a composite
25 − 1 = 31 is a prime → n = 5 is a prime
26 − 1 = 63 = 3 × 5 is a composite → n = 6 is a composite
27 − 1 = 127 is a prime → n = 7 is a prime
28 − 1 = 255 = 5 × 51 is a composite → n = 8 is a composite
29 − 1 = 511 = 7 × 73 is a composite → n = 9 is a composite
210 − 1 = 1023 = 3 × 341 is a composite → n = 10 is a composite
211 − 1 = 2047 = 23 × 89 is a composite → n = 11 is a prime
27. The flow in the Miller-Rabin algorithm may be better understood using the chart in
Figure S9.27. We follow the chart in each case.
4
Choose a base
Find m and k
T am mod n
[T = +
− 1] Pseudoprime
Loop
T T2 mod n
[T = +
− 1] [All k’s tested?]
T = +1: Composite
T = −1: Pseudoprime Composite
In this case, the test declares the integer 2047 as a pseudoprime, which is actu-
ally a composite.
29.
a. We test the claim using (3 − 2)p mod p = (3p − 2) mod p with x = 3, a = 2, and
some small primes.
p=2 (3 − 2)2 mod 2 = 1 (32 − 2) mod 2 = 1
p=3 (3 − 2)3 mod 3 = 1 (33 − 2) mod 2 = 1
p=7 (3 − 2)5 mod 7 = 1 (37 − 2) mod 7 = 1
31.
a.
a1 = 2 m1 = 7 a2 = 3 m2 = 9 → M = 63
−1 −1
M1 = 9 M1 = 9 mod 7 = 4 ; M2 = 7 M2−1 = 7−1 mod 9 = 4
x = (2 × 9 × 4 + 3 × 7 × 4) mod 63 = 30
b.
a1 = 4 m1 = 5 a2 = 10 m2 =11 → M = 55
−1 −1
M1 = 11 M1 = 11 mod 5 = 1 ; M2 = 5 M2−1 = 5−1 mod 11 = 9
x = (4 × 11 × 1 + 10 × 5 × 9) mod 55 = 54
c.
a1 = 7 m1 = 13 a2 = 11 m2 =12 → M = 156 M1 = 12 M2 = 13
M1 = 12 M1−1 = 12−1 mod 13 = 12 ; M2 = 13 M2−1 = 13−1 mod 12 = 1
x = (7 × 12 × 12 + 11 × 13 × 1) mod 156 = 59
6
33.
a. The integer 4 is a QR in Z7∗. Since 7 = 4 × k + 3 with k = 1, we can use the
following expressions to find the solutions.
x: 4(7 + 1)/4 mod 7 = 2 x: −4(7 + 1)/4 mod 7 = −2
c. The integer 7 is not a QR in Z13∗ (see Exercise 32). This equation has no solu-
tions.
d. The integer 12 is not a QR in Z17∗ (see Exercise 32). This equation has no
solutions.
35. We use tables based on Figure 9.7. We first calculate all powers of a’s.
a. y = 2124 mod 8 → a = 21, x = 24 = 110002. Shaded areas represent no moutipli-
cations. All calculations are in modulo 8. The answer is y = 1.
a’s xi y = 1 mod 8
a = 5 mod 8
1
0 y = 1 mod 8
a = 1 mod 8
2 0 y = 1 mod 8
a4 = 1 mod 8 0 y = 1 mod 8
a = 1 mod 8
8
1 y = 1 × 1 mod 8 = 1 mod 8
16
a = 1 mod 8 1 y = 1 × 1 mod 8 = 1 mod 8
c.
y = 177641 mod 2134 → a = 1776, x = 41 = 1010012. Shaded areas represent no
multiplications. All calculations are in modulo 2134. The answer is y = 698.
a’s xi y = 1 mod 2134
a1 = 1776 mod 2134 1 y = 1 × 1776 mod 2134 = 1776 mod 2134
2
a = 124 mod 2134 0 y = 1776 mod 2134
4
a = 438 mod 2134 0 y = 1776 mod 2134
8
a = 1918 mod 2134 1 y = 1776 × 1918 mod 2134 = 504 mod 2134
a16 = 1842 mod 2134 0 y = 504 mod 2134
32
a = 2038 mod 2134 1 y = 504 × 2038 mod 2134 = 698 mod 2134
We then apply the function L3 to both sides of the congruence. Note that the
working modulus is φ(17) = 16 and L3(11) = 7 (from the table).
L3 (x5) ≡ L3 (11) (mod 16) → 5 × L3 (x) ≡ 7 (mod 16) → 5 × L3 (x) ≡ 7 (mod 16)
Now we need to solve the congruence equation 5 × L3 (x) ≡ 7 (mod 16). Recall
from Chapter 2 that this equation has only one solution because gcd (5, 16) = 1.
8
Now we can use the table to find x if L3 (x) = 11; the answer is x = 7, which can be
checked as 75 ≡ 11 (mod 17). We can also write a program to test all of values of x
from 1 to 17 to see if any of this values satisfies the equation. We did so; the
only value is x = 7.
b. To solve the equation 2x11 ≡ 22 (mod 19) or 2x11 ≡ 3 (mod 19), we need to find
a primitive root in the group G = <Z19∗, × > and the discrete logarithm table for
that root. The first primitive root in this group is 2 (see Exercise 36). The dis-
crete logarithm table for this root (base) can be found as
x 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
L2 x 18 1 13 2 16 14 6 3 8 17 12 15 5 7 11 4 10 9
We then apply the function L2 to both sides of the congruence. Note that the
working modulus is φ(19) = 18, L2(2) = 1 and L2(3) = 13.
L2 (2x11) ≡ L2 (3) (mod 18) → L2 (2) + 11 × L2 (x) ≡ L2 (3) (mod 18)
→ 1 + 11 × L2 (x) ≡ 13 (mod 18) → 11 × L2 (x) ≡ 12 (mod 18)
Now we need to solve the congruence equation 11 × y ≡ 12 (mod 18). Recall from
Chapter 2 that this equation has only one solution because gcd (11, 18) = 1.
Now we can use the table to find x if L2 (x) = 6; the answer is x = 7, which can be
checked as 2 × 711 ≡ 3 (mod 19). We can also write a program to test all of values
of x from 1 to 19 to see if any of this values satisfies the equation. We did so;
the only value is x = 7.
c. The equation 5x12 + 6x ≡ 8 (mod 23) cannot be solved using the discrete loga-
rithm discussed in this chapter because there is no property of discrete loga-
rithm to allows us extract L (x) from L (5x12 + 6x). However, we can write a
program to test all of values of x from 1 to 22 to see if any of this values satis-
fies the equation. We did so, but find no value of x satisfying the congruence;
the congruence has no solution.
39. One million operations per second means 3,600,000,000 operations per hour.
a. The complexity of trial division method is exponential (2nb).
41.
Square_and_Multiply (a, x, n)
{
y ←1
for (i = nb −1 downto 0)
{
a ← a2 mod n
if (xi = 1)
y ← y × a mod n
}
return y
}
43.
FermatPrimalityTest (a, n) // We can use different bases
{
y ← Square_and_Multiply (a, n − 1, n) // See Algorithm 9.7 in the text
if (y = 1)
return (n is probably a prime)
return (n is a composite)
}
10
45.
ChineseRemainderTheorem(k, a[1 … k], m[1 … k])
{
M←1
for (i = 1 to k)
M ← M × m[i]
for (i = 1 to k)
{
M[i] ← M / m[i]
InvM[i] ← M[i]−1 mod m[i]
}
x←0
for (i = 1 to k)
x ← [x + (a[i] × M[i] × InvM[i])] mod M
return x
}
47.
FindFirstPrimitiveRoot (p) // p is a prime
{
for (a = 2 to p −1)
{
i ←1
while (ai mod p ≠ 1)
{
i ←i +1
}
if (i = p − 1) // order a = φ(p)
return a
}
}
49.
FindAllDiscreteLogs (p) // p is a prime
{
PrimitiveRootList ← FindAllPrimitiveRoots (p) // See Exercise 48
Create a DiscreteLogTable sorted on y
for (each g in PrimitiveRootList)
{
for (x = 1 to p − 1)
{
y ← gx mod p
insert x to Lg row of DiscreteLogTable under y column
}
}
return DiscreteLogTable
}