Solution
Solution
Alvin Lin
January 2018 - May 2018
Exercise 1
Find the value of the Euler totient function (n) for n = 937, 938, 939, 940, 941, 942. Show the details of
computations.
• (937) = 936
937 = 9371
(937) = (9371 9360 ) = (937 1) = 936
• (938) = 396
938 = 21 ⇥ 71 ⇥ 671
(938) = (21 20 ) ⇥ (71 70 ) ⇥ (671 670 )
= 1 ⇥ 6 ⇥ 66 = 396
• (939) = 624
939 = 3 ⇥ 313
(939) = (31 30 ) ⇥ (3131 3130 ) = 2 ⇥ 312 = 624
• (940) = 368
940 = 22 ⇥ 5 ⇥ 47
(940) = (22 21 ) ⇥ (51 50 ) ⇥ (471 470 )
= 2 ⇥ 4 ⇥ 46 = 368
• (941) = 940
941 = 9411
(941) = (9411 9410 ) = 940
• (942) =
942 = 2 ⇥ 3 ⇥ 157
(942) = (21 20 ) ⇥ (31 30 ) ⇥ (1571 1570 )
= 1 ⇥ 2 ⇥ 156 = 312
1
Exercise 2
Compute 4141 mod 937, using the modular square and multiply exponentiation algorithm. Show the
details of the computation.
41 = 1010012
Step Accumulated Result Binary Exponent
1 r = 12 ⇥ 41 ⌘ 41 mod 937 1
2 r = 412 ⌘ 744 mod 937 10
3 r = 7442 ⇥ 41 ⌘ 836 mod 937 101
4 r = 8362 ⌘ 831 mod 937 1010
5 r = 8312 ⌘ 929 mod 937 10100
6 r = 9292 ⇥ 41 ⌘ 750 mod 937 101001
Exercise 3
Use the extended Euclidean algorithm to find the multiplicative inverse of 27 module n, if it exists, for
n = 1033, 1034, 1035. Show the details of the computations.
1
• 27 mod 1033 = 880
1033 = 38 ⇥ 27 + 7
27 = 3 ⇥ 7 + 6
7=1⇥6+1
6=6⇥1+0
gcd(1033, 27) = 1
1=7 1⇥6
1 = 7 (27 3 ⇥ 7)
= 27 + 4 ⇥ 7
= 27 + 4 ⇥ (1033 38 ⇥ 27)
= 153 ⇥ 27 + 4 ⇥ 1033
= 153 ⇥ 27 mod 1033
1
27 = 880 mod 1033
2
1
• 27 mod 1034 = 383
1034 = 38 ⇥ 27 + 8
27 = 3 ⇥ 8 + 3
8=2⇥3+2
3=1⇥2+1
gcd(1034, 27) = 1
1=3 1⇥2
= 3 (8 2 ⇥ 3)
= 8+3⇥3
= 8 + 3 ⇥ (27 3 ⇥ 8)
= 3 ⇥ 27 10 ⇥ 8
= 3 ⇥ 27 10 ⇥ (1034 38 ⇥ 27)
= 383 ⇥ 27 10 ⇥ 1034
= 383 ⇥ 27 mod 1034
27 1 = 383 mod 1034
1
• 27 mod 1035 =
1035 = 38 ⇥ 27 + 9
27 = 3 ⇥ 9 + 0
Exercise 4
For each of the following compute the value of or argue that it is not defined. For at least two of the six
cases below, do the computations without using any program, and describe briefly how you did it.
3x mod 11 ⌘ 2
31 mod 11 ⌘ 3
32 mod 11 ⌘ 9 mod 11 ⌘ 9
33 mod 11 ⌘ 9 ⇥ 3 mod 11 ⌘ 5
34 mod 11 ⌘ 5 ⇥ 3 mod 11 ⌘ 4
35 mod 11 ⌘ 4 ⇥ 3 mod 11 ⌘ 1
36 mod 11 ⌘ 1 ⇥ 3 mod 11 ⌘ 31 mod 11 ⌘ 3
We can calculate the discrete logarithm by brute force starting from an exponent of 1. This discrete
logarithm is not defined since the modulo cycles and is not evenly distributed among all the numbers
from 1 to 11.
3
• discrete logarithm of 3 base 2 mod 19
2x mod 19 ⌘ 3
21 mod 19 ⌘ 2 mod 19 ⌘ 2
22 mod 19 ⌘ 2 ⇥ 2 mod 19 ⌘ 4
23 mod 19 ⌘ 4 ⇥ 2 mod 19 ⌘ 8
24 mod 19 ⌘ 8 ⇥ 2 mod 19 ⌘ 16
25 mod 19 ⌘ 16 ⇥ 2 mod 19 ⌘ 13
26 mod 19 ⌘ 13 ⇥ 2 mod 19 ⌘ 7
27 mod 19 ⌘ 7 ⇥ 2 mod 19 ⌘ 14
28 mod 19 ⌘ 14 ⇥ 2 mod 19 ⌘ 9
29 mod 19 ⌘ 9 ⇥ 2 mod 19 ⌘ 18
210 mod 19 ⌘ 18 ⇥ 2 mod 19 ⌘ 17
211 mod 19 ⌘ 17 ⇥ 2 mod 19 ⌘ 15
212 mod 19 ⌘ 15 ⇥ 2 mod 19 ⌘ 11
213 mod 19 ⌘ 11 ⇥ 2 mod 19 ⌘ 3
x = 13
The discrete logarithm of 3 base 2 mod 19 is 13. 213 mod 19 ⌘ 3.
• discrete logarithm of 3 base 3 mod 97
3x mod 97 ⌘ 3 x = 1
Exercise 5
1
Solve problem 6.10 on page 171. Show the details of the computations. Compute the inverse a mod n
with Fermat’s Theorem (if applicable) or Euler’s Theorem:
• a = 4, n = 7
1
a = ap 2
mod p if p is prime
1
4 = 47 2
mod 7
= 45 mod 7 = 2
4
• a = 5, n = 12
12 = 2 ⇥ 5 + 2
5=2⇥2+1
gcd(12, 5) = 1
1 = 5 (2 ⇥ 2)
= 5 2 ⇥ (12 2 ⇥ 5)
= 5 ⇥ 5 2 ⇥ 12
= 5 ⇥ 5 mod 12
1
5 = 5 mod 12
• a = 6, n = 13
1
a = ap 2 mod p if p is prime
1
6 = 613 2 mod 13
= 611 mod 13 = 11
Exercise 6
Solve problem 7.1 on page 200. Show the details of the computations. Let the two primes p = 41 and
q = 17 be given as set-up parameters for RSA.
1. Which of the parameters e1 = 32, e2 = 49 is a valid RSA exponent? Justify your choice.
n = pq = 41 ⇥ 17 = 697
(n) = (p 1)(q 1) = 640
gcd( (n), e1 ) = gcd(640, 32) = 32
gcd( (n), e2 ) = gcd(640, 49) = 1
2. Compute the corresponding private key Kpr = (p, q, d). Use the extended Euclidean algorithm for
the inversion and point out every calculation step.
(n) = 640 e = 49
de ⌘ 1 mod (n)
640 = 13 ⇥ 49 + 3
49 = 16 ⇥ 3 + 1
gcd(640, 49) = 1
1 = 49 16 ⇥ 3
= 49 16 ⇥ (640 13 ⇥ 49)
= 209 ⇥ 49 16 ⇥ 640
= 209 ⇥ 49 mod 640
d = e 1 = 209
5
Exercise 7
Solve problem 7.2 on page 200. Show the details of the computations. Computing modular exponentiation
efficiently is inevitable for the practicability of RSA. Compute the following exponentiations xe mod m
applying the square and multiply algorithm:
1. x = 2, e = 79, m = 101
79 = 10011112
2. x = 3, e = 197, m = 101
197 = 110001012
Exercise 8
Solve problem 7.3 on page 200. Show the details of the computations. Encrypt and decrypt by means of
the RSA algorithm with the following system parameters:
• p = 3, q = 11, d = 7, x = 5
n = pq = 33
(n) = (33) = (11 1)(3 1) = 20
de ⌘ 1 mod (n)
e = d 1 mod (n) = 3 mod 20
y = xe mod n = 53 mod 33 = 26
6
• p = 5, q = 11, e = 3, x = 9
n = pq = 55
(n) = (55) = (11 1)(5 1) = 40
de ⌘ 1 mod (n)
d = e 1 mod (n) = 27 mod 40
y = xd mod n = 927 mod 55 = 4