Iss 12 08
Iss 12 08
Iss 12 08
Cryptography
Objectives
❏ To introduce prime numbers and their applications
in cryptography.
❏ To discuss some primality test algorithms and their
efficiencies.
❏ To discuss factorization algorithms and their
applications in cryptography.
❏ To describe the Chinese remainder theorem and its
application.
❏ To introduce quadratic congruence.
❏ To introduce modular exponentiation and
logarithm.
PRIMES
1 Definition
2 Cardinality of Primes
3 Checking for Primeness
4 Euler’s Phi-Function
5 Fermat’s Little Theorem
6 Euler’s Theorem
7 Generating Primes
Definition
Three groups of positive integers
Note
A prime is divisible only by itself and 1.
Example
What is the smallest prime?
Solution
The smallest prime is 2, which is divisible by 2 (itself) and 1.
Example
List the primes smaller than 10.
Solution
There are four primes less than 10: 2, 3, 5, and 7. It is interesting
to note that the percentage of primes in the range 1 to 10 is 40%.
The percentage decreases as the range increases.
Cardinality of Primes
Number of Primes in n
Example
As a trivial example, assume that the only primes are in the set
{2, 3, 5, 7, 11, 13, 17}. Here P = 510510 and P + 1 = 510511.
However, 510511 = 19 × 97 × 277; none of these primes were in the
original list. Therefore, there are three primes greater than 17.
Example
Solution
The approximation gives the range 72,383 to 78,543. The actual
number of primes is 78,498.
Checking for Primeness
Is 97 a prime?
Solution
The floor of 97 = 9. The primes less than 9 are 2, 3, 5, and 7. We
need to see if 97 is divisible by any of these numbers. It is not, so
97 is a prime.
Example
Is 301 a prime?
Solution
The floor of 301 = 17. We need to check 2, 3, 5, 7, 11, 13, and 17.
The numbers 2, 3, and 5 do not divide 301, but 7 does. Therefore
301 is not a prime.
Sieve of Eratosthenes
Euler’s Phi-Function
Note
The difficulty of finding f(n) depends on the
difficulty of finding the factorization of n.
Example
What is the value of f(13)?
Solution
Because 13 is a prime, f(13) = (13 −1) = 12.
Example
What is the value of f(10)?
Solution
We can use the third rule: f(10) = f(2) × f(5) = 1 × 4 = 4, because 2
and 5 are primes.
Example
What is the value of f(240)?
Solution
We can write 240 = 24 × 31 × 51. Then
Example
Can we say that f(49) = f(7) × f(7) = 6 × 6 = 36?
Solution
No. The third rule applies when m and n are relatively prime.
Here 49 = 72. We need to use the fourth rule: f(49) = 72 − 71 = 42.
Example
What is the number of elements in Z14*?
Solution
The answer is f(14) = f(7) × f(2) = 6 × 1 = 6. The members are 1,
3, 5, 9, 11, and 13.
Note
Interesting point: If n > 2, the value of f(n) is even.
Fermat’s Little Theorem
p is a prime, a is an integer, and p does not divide a.
First Version
ap − 1 ≡ 1 mod p
Second Version
ap ≡ a mod p
Example
Find the result of 610 mod 11.
Solution
We have 610 mod 11 = 1. This is the first version of Fermat’s little
theorem where p = 11.
Example
Find the result of 312 mod 11.
Solution
Here the exponent (12) and the modulus (11) are not the same.
With substitution this can be solved using Fermat’s little theorem.
Multiplicative Inverses
Multiply both side of Fermat’s little theorem (1st version)
by a.
Example
The answers to multiplicative inverses modulo a prime can be
found without using the extended Euclidean algorithm:
Euler’s Theorem
af(n) ≡ 1 (mod n)
Second Version: if n = p x q, a<n, and k an integer.
a k × f(n) + 1 ≡ a (mod n)
Note
The second version of Euler’s theorem is used in the
RSA cryptosystem.
Quickly finding a solution to exponentiation.
Example
Solution
We have 624 mod 35 = 6f(35) mod 35 = 1.
Example
Find the result of 2062 mod 77.
Solution
If we let k = 1 on the second version, we have
2062 mod 77 = (20 mod 77) (20f(77) + 1 mod 77) mod 77
= (20)(20) mod 77 = 15.
Multiplicative Inverses
Euler’s theorem can be used to find multiplicative
inverses modulo a composite.
Mersenne Primes
If p is a prime.
Note
A number in the form Mp = 2p − 1 is called a
Mersenne number and may or may not be a prime.
Fermat Primes
F0 = 3 F1 = 5 F2 = 17 F3 = 257 F4 = 65537
F5 = 4294967297 = 641 × 6700417 Not a prime
PRIMALITY TESTING
1 Deterministic Algorithms
2 Probabilistic Algorithms
3 Recommended Primality Test
Deterministic Algorithms
Divisibility Algorithm
Note
The bit-operation complexity of the divisibility test
is exponential.
Example
Assume n has 200 bits. What is the number of bit operations
needed to run the divisibility-test algorithm?
Solution
The bit-operation complexity of this algorithm is 2n /2. This means
b
Example
Assume n has 200 bits. What is the number of bit operations
needed to run the AKS algorithm?
Solution
This algorithm needs only (log2200)12 = 39,547,615,483 bit
operations. On a computer capable of doing 1 billion bit
operations per second, the algorithm needs only 40 seconds.
AKS Algorithm
Probabilistic Algorithms
Fermat Test
Example
Does the number 561 pass the Fermat test?
Solution
Use base 2
The number passes the Fermat test, but it is not a prime, because
561 = 33 × 17.
Example
Suppose we wish to determine if n = 221 is prime.
Randomly pick 1 ≤ a < 221, say a = 38.
Check the equality:
Solution
Use base 2
The number passes the Fermat test, but it is not a prime, because
561 = 33 × 17.
Square Root Test
Example
What are the square roots of 1 mod n if n is 7 (a prime)?
Solution
The only square roots are 1 and −1. We can see that
Example
What are the square roots of 1 mod n if n is 7 (a prime)?
Solution
The only square roots are 1 and −1. We can see that
Solution
There are four solutions: 1, 3, 5, and 7 (which is −1). We can see
that
Example
What are the square roots of 1 mod n if n is 17 (a prime)?
Solution
There are only two solutions: 1 and −1
Example
What are the square roots of 1 mod n if n is 22 (a composite)?
Solution
Surprisingly, there are only two solutions, +1 and −1, although 22
is a composite.
Miller-Rabin Test
Note
The Miller-Rabin test needs from step
0 to step k − 1.
Example
Does the number 561 pass the Miller-Rabin test?
Solution
Using base 2, let 561 − 1 = 35 × 24, which means m = 35, k = 4, and
a = 2.
Example
We already know that 27 is not a prime. Let us apply the Miller-
Rabin test.
Solution
With base 2, let 27 − 1 = 13 × 21, which means that m = 13, k = 1,
and a = 2. In this case, because k − 1 = 0, we should do only the
initialization step: T = 213 mod 27 = 11 mod 27. However, because
the algorithm never enters the loop, it returns a composite.
Example
We know that 61 is a prime, let us see if it passes the Miller-Rabin
test.
Solution
We use base 2.
Recommended Primality Test
Solution
1. Perform the divisibility tests first. The numbers 2, 3, 5, 7, 11, 17,
and 23 are not divisors of 4033.
2. Perform the Miller-Rabin test with a base of 2, 4033 − 1 = 63 ×
26, which means m is 63 and k is 6.
Example
Example
Use the trial division algorithm to find the factors of 1523357784.
Solution
We run a program based on the algorithm and get the following
result.
Fermat Method
CHINESE REMAINDER THEOREM
The solution to this set of equations is given in the next section; for
the moment, note that the answer to this set of equations is x = 23.
This value satisfies all equations: 23 ≡ 2 (mod 3), 23 ≡ 3 (mod 5),
and 23 ≡ 2 (mod 7).
Solution To Chinese Remainder Theorem
Solution
We follow the four steps.
1. M = 3 × 5 × 7 = 105
1 Exponentiation
2 Logarithm
Exponentiation
Fast Exponentiation