Unit 2.1
Unit 2.1
S.Y. SECTION A, B, C
ADVANCED CRYPTOGRAPHY
UNIT 2
Because learning changes
®
everything.
Unit No 2
Cryptographic Mathematics
© McGraw Hill LLC. All rights reserved. No reproduction or distribution without the prior written consent of McGraw Hill LLC.
Chapter Motivation
Number theory is the part of mathematics devoted to the study of
the integers and their properties.
Key ideas in number theory include divisibility and the primality of
integers.
Representations of integers, including binary and hexadecimal
representations, are part of number theory.
Number theory has long been studied because of the beauty of its
ideas, its accessibility, and its wealth of open questions.
We’ll use many ideas developed in Chapter 1 about proof methods
and proof strategy in our exploration of number theory.
Mathematicians have long considered number theory to be pure
mathematics, but it has important applications to computer
science and cryptography studied in Sections 4.5 and 4.6.
© McGraw Hill LLC 3
Chapter Summary
Divisibility and Modular Arithmetic.
Integer Representations and Algorithms.
Primes and Greatest Common Divisors.
Solving Congruences.
Applications of Congruences.
Cryptography.
Division.
Division Algorithm.
Modular Arithmetic.
Integer Representations.
• Base b Expansions.
• Binary Expansions.
• Octal Expansions.
• Hexadecimal Expansions.
Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F
Octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17
Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111
for j := 0 to n − 1
iftbj = 1 hen c j = a shifted j places
else c j :0
co , c1 ,..., cn-1 are the partial products
p := 0
for j := 0 to n − 1
p := p + c j
return p {p is the value of ab}
The number of additions of bits used by the algorithm to multiply two
n-bit integers is O n .
2
2
O log m log n bit operations are used to find bn mod m.
© McGraw Hill LLC 34
Primes and Greatest
Common Divisors
Section 2.4
If an integer n is a
composite integer, then
it has a prime divisor
less than or equal to √n.
To see this, note that if
n = ab, then a ≤ √n or b
≤√n.
Trial division, a very
inefficient method of
determining if a number
n is prime, is to try
every integer i ≤√n and
see if n is divisible by i.
Access the text alternative for slide images.
Finding the gcd of two positive integers using their prime factorizations
is not efficient because there is no efficient algorithm for finding the
prime factorization of a positive integer.
© McGraw Hill LLC 49
Least Common Multiple
Definition: The least common multiple of the positive integers a and b is
the smallest positive integer that is divisible by both a and b. It is
denoted by lcm(a,b).
The least common multiple can also be computed from the prime
factorizations. max a1 ,b1 max a2 ,b2 max an ,bn
lcm a , b p1 p2 pn ,
This number is divided by both a and b and no smaller number is divided
by a and b.
Example: lcm 2 3 7 , 2 3 = 2
3 5 2 4 3 max 3,4 max 5,3 max 2,0
3 7 = 2 4 3 5 72
The greatest common divisor and the least common multiple of two
integers are related by:
Theorem 5: Let a and b be positive integers. Then
ab = gcd(a,b) lcm(a,b)
(proof is Exercise 31)
© McGraw Hill LLC 50
Euclidean Algorithm 1
• 14 = 7 2 0 Divide 14 by 7
Stopping condition
r0 r1q1 r2 0 r2 r1 ,
Suppose that a and b are positive
r1 r2q2 r3 0 r3 r2 ,
integers with a ≥ b. .
Let r0 = a and r1 = b. .
.
Successive applications of the division rn 2 rn 1qn 1 r2 0 rn rn 1 ,
algorithm yields: rn 1 rnqn .
Linear Congruences.
The Chinese Remainder Theorem.
Computer Arithmetic with Large Integers (not
currently included in slides, see text).
Fermat’s Little Theorem.
Pseudorandom.
Primitive Roots and Discrete Logarithms.
n 1
Given a positive integer n, such that 2 ≡ 1 (mod n):
• If n does not satisfy the congruence, it is composite.
(optional) Carmichael
(1879-1967)
There are composite integers n that pass all tests with bases
b such that gcd(b,n) = 1.
n 1
Definition: A composite integer n that satisfies the congruence b ≡ 1 (mod n)
for all positive integers b with gcd(b,n) = 1 is called a Carmichael number.
Example: The integer 561 is a Carmichael number. To see this:
• 561 is composite, since 561 = 3 11 13.
• If gcd(b, 561) = 1, then gcd(b, 3) = 1, then gcd(b, 11) = gcd(b, 17) =1.
• Using Fermat’s Little Theorem: b2 1 mod 3 , b10 1 mod 11 , b16 1 mod 17 .
• Then
280
b560 b2
1 mod 3 ,
b560 b
10 56
1 mod 11 ,
b560 b
16 35
1 mod 17 .
560
• It follows (see Exercise 29) that b ≡ 1 (mod 561) for all positive integers b with
gcd(b,561) = 1. Hence, 561 is a Carmichael number.
Even though there are infinitely many Carmichael numbers, there are other tests
(described in the exercises) that form the basis for efficient probabilistic
primality testing. (see Chapter 7)
© McGraw Hill LLC 75
Primitive Roots
Definition: A primitive root modulo a prime p is an integer r in Z p
such that every nonzero element of Z p is a power of r.
Example: Since every element of Z11 is a power of 2, 2 is a
primitive root of 11.
1 2 3 4 5 6
Powers of 2 modulo 11: 2 = 2, 2 = 4, 2 = 8, 2 = 5, 2 = 10, 2 = 9,
27 = 7, 28 = 3, 210 = 2.
Example: Since not all elements of Z11 are powers of 3, 3 is not a
primitive root of 11.
1 2 3 4 5
Powers of 3 modulo 11: 3 = 3, 3 = 9, 3 = 5, 3 = 4, 3 = 1 , and the
pattern repeats for higher powers.
Important Fact: There is a primitive root modulo p for every prime
number p.
© McGraw Hill LLC 76
Discrete Logarithms
Suppose p is prime and r is a primitive root modulo p. If a is an integer between
e
1 and p −1, that is an element ofZ p , there is a unique exponent e such that r =
a in Z p , that is, r e mod p = a.
Definition: Suppose that p is prime, r is a primitive root modulo p, and a is an
e
integer between 1 and p −1, inclusive. If r mod p = a and 1 ≤ e ≤ p − 1, we say
that e is the discrete logarithm of a modulo p to the base r and we write log r a =
e (where the prime p is understood).
Example 1: We write log 2 3 = 8 since the discrete logarithm of 3 modulo 11
to
the base 2 is 8 as 28 = 3 modulo 11.
Example 2: We write log2 5 = 4 since the discrete logarithm of 5 modulo 11
4
the base 2 is 4 as 2 = 5 modulo
to 11.
There is no known polynomial time algorithm for computing the discrete
logarithm of a modulo p to the base r (when given the prime p, a root r modulo
p, and a positive integer a ∊Z p). The problem plays a role in cryptography as will
be discussed in Section 4.6.
© McGraw Hill LLC 77
Applications of Congruences
Section 2.5
Hashing Functions.
Pseudorandom Numbers.
Check Digits.
x0 = 3.
Solution: Compute the terms of the sequence by successively using the congruence
xn1 7 xn 4 mod 9, with x0 3.
x1 7 x0 4 mod 9 7 3 4 mod 9 25 mod 9 7,
x2 7 x1 4 mod 9 7 7 4 mod 9 53 mod 9 8,
x3 7 x2 4 mod 9 7 8 4 mod 9 60 mod 9 6,
x4 7 x3 4 mod 9 7 6 4 mod 9 46 mod 9 1,
x5 7 x4 4 mod 9 7 1 4 mod 9 11 mod 9 2,
x6 7 x5 4 mod 9 7 2 4 mod 9 18 mod 9 0,
x7 7 x6 4 mod 9 7 0 4 mod 9 4 mod 9 4,
x8 7 x7 4 mod 9 7 4 4 mod 9 32 mod 9 5,
x9 7 x8 4 mod 9 7 5 4 mod 9 39 mod 9 3.
A single error is an error in one digit of an identification number and a transposition error is the
accidental interchanging of two digits. Both of these kinds of errors can be detected by the check
digit for ISBN-10. (see text for more details)
© McGraw Hill LLC 84
Section Summary 6
Classical Cryptography.
Cryptosystems.
Public Key Cryptography.
RSA Cryptosystem.
Cryptographic Protocols.
Primitive Roots and Discrete Logarithms.
Julius Caesar created secret messages by shifting each letter three letters forward in the
alphabet (sending the last three letters to the first three letters.) For example, the letter
B is replaced by E and the letter X is replaced by A. This process of making a message
secret is an example of encryption.
Here is how the encryption process works:
• Replace each letter by an integer from Z 26 , that is an integer from 0 to 25 representing one less
than its position in the alphabet.
• The encryption function is f(p) = (p + 3) mod 26. It replaces each integer p in the set 0,1,2,...,25
by f(p) in the set 0,1,2,...,25 .
• Replace each integer p by the letter with the position p + 1 in the alphabet.
Example: Encrypt the message “MEET YOU IN THE PARK” using the Caesar cipher.
Solution: 12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10.
Now replace each of these numbers p by f(p) = (p + 3) mod 26.
15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13.
Translating the numbers back to letters produces the encrypted message
“PHHW BRX LQ WKH SDUN.”
© McGraw Hill LLC 86
Caesar Cipher 2
To recover the original message, use f 1(p) = (p−3) mod 26. So,
each letter in the coded message is shifted back three letters in
the alphabet, with the first three letters sent to the last three
letters. This process of recovering the original message from the
encrypted message is called decryption.
The Caesar cipher is one of a family of ciphers called shift
ciphers. Letters can be shifted by an integer k, with 3 being just
one possibility. The encryption function is
f(p) = (p + k) mod 26
and the decryption function is
f 1(p) = (p−k) mod 26
The integer k is called a key.
© McGraw Hill LLC 87
Shift Cipher 1
A public key cryptosystem, now known as the RSA system was introduced in
1976 by three researchers at MIT.
It is now known that the method was discovered earlier by Clifford Cocks,
working secretly for the UK government.
RSA works as a public key system since the only known method of finding d is based on
a factorization of n into primes. There is currently no known feasible method for
factoring large numbers into primes.
Example: The message 0981 0461 is received. What is the decrypted message if it was
encrypted using the RSA cipher from the previous example.
Solution: The message was encrypted with n = 43 59 and exponent 13. An inverse of
13 modula 42 58 = 2436 (exercise 2 in Section 4.4) is d = 937.
• Since 0981937 mod 2537 0704 and 0461937 mod 2537 = 1115, the decrypted message is 0704
1115. Translating back to English letters, the message is HELP.
© McGraw Hill LLC 99
Cryptographic Protocols: Key Exchange
Cryptographic protocols are exchanges of messages carried out by two or more parties
to achieve a particular security goal.
Key exchange is a protocol by which two parties can exchange a secret key over an
insecure channel without having any past shared secret information. Here the Diffe-
Hellman key agreement protocol is described by example.
i. Suppose that Alice and Bob want to share a common key.
ii. Alice and Bob agree to use a prime p and a primitive root a of p.
k1
iii. Alice chooses a secret integer k1 and sends a mod p to Bob.
iv. Bob chooses a secret integer k2 and sends a k 2 mod p to Alice.
Alice computes a mod p.
k 2 k1
v.
Bob computes a mod p.
k1 k 2
vi.
At the end of the protocol, Alice and Bob have their shared key
a mod p = a mod p.
k 2 k1 k1 k 2
To find the secret information from the public information would require the adversary
k1 k2
to find k1 and k2 from a mod p and a mod p respectively. This is an instance of the
discrete logarithm problem, considered to be computationally infeasible when p and a
are sufficiently large.
© McGraw Hill LLC 100
Cryptographic Protocols: Digital
Signatures 1
Alice wants to send a message M so that everyone who receives the message
knows that it came from her.
1. She translates the message to numerical equivalents and splits into blocks,
just as in RSA encryption.
2. She then applies her decryption function Dn ,e to the blocks and sends the
results to all intended recipients.
3. The recipients apply Alice’s encryption function and the result is the original
plain text since En ,e Dn ,e x = x.
Everyone who receives the message can then be certain that it came from Alice.
© McGraw Hill LLC 101
Cryptographic Protocols: Digital
Signatures 2
Example: Suppose Alice’s RSA cryptosystem is the same as in the earlier example with
key(2537,13), 2537 = 43 59, p = 43 and q = 59 are primes and
gcd e , p 1 q 1 = gcd 13, 42 58 = 1.
Her decryption key is d = 937.
She wants to send the message “MEET AT NOON” to her friends so that they can be
certain that the message is from her.
Solution: Alice translates the message into blocks of digits 1204 0419 0019 1314 1413.
1. She then applies her decryption transformation D2537,13 x = x mod 2537 to each
937
block.
2. She finds (using her laptop, programming skills, and knowledge of discrete
937 937 937
mathematics) that 1204 mod 2537 = 817, 419 mod 2537 = 555, 19 mod
2537 = 1310, 1314 937 mod 2537 = 2137, and 1413937 mod 2537 = 1026.
3. She sends 0817 0555 1310 2173 1026.
When one of her friends receive the message, they apply Alice’s encryption
transformation E2537,13 to each block. They then obtain the original message which they
translate back to English letters.