0% found this document useful (0 votes)
29 views

Lecture 4

This chapter discusses number theory and cryptography. It covers topics like divisibility, modular arithmetic, prime numbers, greatest common divisors, congruences, and their applications. The chapter also introduces classical cryptography techniques like the Caesar cipher and affine cipher. It explains how to encrypt and decrypt messages using modular arithmetic and congruences.

Uploaded by

ssk.cmedhealth
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Lecture 4

This chapter discusses number theory and cryptography. It covers topics like divisibility, modular arithmetic, prime numbers, greatest common divisors, congruences, and their applications. The chapter also introduces classical cryptography techniques like the Caesar cipher and affine cipher. It explains how to encrypt and decrypt messages using modular arithmetic and congruences.

Uploaded by

ssk.cmedhealth
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Discrete Mathematics

and Its Applications


Sixth Edition
By Kenneth Rosen

Chapter 4
Number Theory and
Cryptography
歐亞書局
4.1 Divisibility and Modular Arithmetic
4.2 Integer Representations and Algorithms
4.3 Primes and Greatest Common Divisors
4.4 Solving Congruences
4.5 Applications of Congruences
4.6 Cryptography

歐亞書局 P. 167
4.1 Divisibility and Modular
Arithmetic
• Definition 1:
– a and b are integers with a = 0
– We say that a divides b if there is an integer c
such that b = ac
– Equivalently, b/a is an integer
– a is a factor or divisor of b
– b is a multiple of a
– Denoted by a | b
Example
• Let n and d be positive integers. How
many positive integers not exceeding n are
divisible by d?
Theorem 1
• Let a, b, and c be integers, where a = 0.
Then
– (i) if a | b and a | c, then a | (b + c);
– (ii ) if a | b, then a | bc for all integers c;
– (iii ) if a | b and b | c, then a | c.
Corollary 1
• If a, b, and c are integers,
• where a = 0,
• such that a | b and a | c,
• then a | mb + nc whenever m and n are
integers.
The Division Algorithm
• Theorem 2
– Let a be an integer
– and d a positive integer.
– Then there are unique integers q and r, with
0 ≤ r < d,
– such that a = dq + r.
Definition 2
• In the equality given in the division
algorithm, d is called the divisor, a is called
the dividend, q is called the quotient, and r
is called the remainder. This notation is
used to express the quotient and
remainder:
• q = a div d
• r = a mod d
Example
• What are the quotient and remainder
when −11 is divided by 3?

• −11 = 3(−4) + 1
• −11 = 3(−3) − 2

• Which one should we use?


Modular Arithmetic
• Definition 3
– If a and b are integers and m is a positive
integer, then a is congruent to b modulo m if m
divides a − b. We use the notation a ≡ b (mod m)
to indicate that a is congruent to b modulo m.
We say that a ≡ b (mod m) is a congruence and
that m is its modulus (plural moduli). If a and b
are not congruent modulo m, we write
a ≡ b (mod m).
Difference between
a≡ b (mod m) and a mod m = b
• a ≡ b (mod m)
– represents a relation on the set of integers
• a mod m = b
– represents a function
Theorem 3
• Let a and b be integers,
• and let m be a positive integer.
• Then a ≡ b (mod m) if and only if
a mod m = b mod m.
Theorem 4
• Let m be a positive integer.
• The integers a and b are congruent modulo
m if and only if
• There is an integer k
• such that a = b + km.
Theorem 5
• Let m be a positive integer.
• If a ≡ b (mod m) and c ≡ d (mod m), then
• a + c ≡ b + d (mod m) and ac ≡ bd (mod m).
Corollary 2
• Let m be a positive integer
• and let a and b be integers. Then
• (a + b) modm = ((a mod m) + (b mod m)) modm
• and ab modm = ((a mod m)(b mod m)) mod m.
Arithmetic Modulo m
• 𝑍𝑚 = 0, 1, 2, 3, … , 𝑚 − 1
• 𝑎 +𝑚 𝑏 = 𝑎 + 𝑏 𝒎𝒐𝒅 𝑚
• 𝑎.𝑚 𝑏 = 𝑎. 𝑏 𝒎𝒐𝒅 𝑚
Properties
• Closure
• Associativity
• Commutativity
• Identity elements
• Additive inverses
• Distributivity
4.3 Prime
• Definition 1:
– An integer p greater than 1 is called prime if
the only positive factors of p are 1 and p. A
positive integer that is greater than 1 and is
not prime is called composite.
Theorem 1
• THE FUNDAMENTAL THEOREM OF
ARITHMETIC
– Every integer greater than 1 can be written
uniquely as a prime or as the product of two
or more primes where the prime factors are
written in order of non decreasing size.
Theorem 2
• If n is a composite integer, then n has a
prime divisor less than or equal to √n.
Example
• Show that 101 is prime.
The Sieve of Eratosthenes
Theorem 3
• There are infinitely many primes.
Theorem 4
• THE PRIME NUMBER THEOREM
– The ratio of the number of primes not
exceeding x and x/ ln x approaches 1 as x
grows without bound.
Greatest Common Divisors
(GCD)
• Definition:
– Let a and b be integers, not both zero
– The largest integer d such that d | a and d | b
is called the greatest common divisor of a and b
– Denoted by gcd(a, b)
Example
• What is the greatest common divisor of 24
and 36?
– The positive common divisors of 24 and 36
are 1, 2, 3, 4, 6, and 12.
– Hence, gcd(24, 36) = 12.
• What is the greatest common divisor of 17
and 22?
– The integers 17 and 22 have no positive
common divisors other than 1
– Hence, gcd(17, 22) = 1
Pairwise Relatively Prime
• Definition:
– We have integers 𝑎1 , 𝑎2 , … , 𝑎𝑛 .
– They are pairwise relatively prime if
gcd(ai, aj ) = 1 whenever 1 ≤ i < j ≤ n.
Example
• Determine whether the integers 10, 17,
and 21 are pairwise relatively prime

• Determine the integers 10, 19, and 24 are


pairwise relatively prime.
Finding GCD using the Prime
Factorizations
• Example: Find the GCD of 120 and 500
– 120 = 23 × 3 × 5
– 500 = 22 × 53
– gcd(120, 500) = 22 × 5 = 20
Least Common Multiple (LCM)
• Definition:
– Let a and b be integers, not both zero
– The smallest integer d such that a | d and b | d
is called the least common multiple of a and b
– Denoted by lcm(a, b)
Finding LCM using the Prime
Factorizations
• Example: What is the least common
multiple of 23 × 35 × 72 and 24 × 33 ?
– lcm = 24 × 35 × 72
Theorem
• Let a and b be positive integers.
• Then ab = gcd(a, b) × lcm(a, b).
The Euclidean Algorithm
•Find the GCD of 91 and 287 using
the Euclidean Algorithm
– 287 = 91 × 3 + 14
– 91 = 14 × 6 + 7
– 14 = 7 × 2
Lemma 1
• Let a = bq + r
• Where a, b, q, and r are integers.
• Then gcd(a, b) = gcd(b, r).
THEOREM 6
• BÉZOUT’S THEOREM:
• If a and b are positive integers,
• then there exist integers s and t such that
• gcd(a, b) = sa + tb.
Example
• Express gcd(252, 198) = 18 as a linear
combination of 252 and 198
Leamma 2
• If a, b, and c are positive integers such that
gcd(a, b) = 1 and a | bc, then a | c.
Lemma 3
• If p is a prime and p | a1.a2 ・ ・ ・ an,
where each ai is an integer, then p | ai for
some i.
Proof (of the uniqueness of the
prime factorization of a positive
integer):
Theorem 7
• Let m be a positive integer and let a, b, and
c be integers. If ac ≡ bc (mod m) and
gcd(c,m) = 1, then a ≡ b (mod m).
Linear Congruence
• A congruence of the form
ax ≡ b (mod m)
• Where, m is a positive integer
• a and b are integers
• x is a variable
How to find x?
• When x is solvable there will be infinite
possible solutions to x
• Find the integer 𝑎ത such that
• 𝑎 × 𝑎ത = 1(𝑚𝑜𝑑 𝑚)
• 𝑎ത is the invers of a modulo m
Theorem 1
• If a and m are relatively prime integers
• and m > 1
• then an inverse of a modulo m exists
• (there is only a single value of 𝑎ത such that
0 ≤ 𝑎ത < m)
• All the values of 𝑎ത are congruent to 𝑎ത
modulo m
How to find the 𝑎?

• Brute force algorithm
• Extension of Euclidean algorithm
Example
• What are the solutions of the linear
congruence 3x ≡ 4 (mod 7)?
Chinese Remainder Theorem
• Used to find the solution to a system of
congruence such as:
• x ≡ 2 (mod 3),
• x ≡ 3 (mod 5),
• x ≡ 2 (mod 7)
Chinese Remainder Theorem (CRT)
• Let 𝑚1 , 𝑚2 , … , 𝑚𝑛 be pairwise relatively prime
positive integers greater than one
• and 𝑎1 , 𝑎2 , … , 𝑎𝑛 be arbitrary integers
• Then the system
𝑥 ≡ 𝑎1 𝑚𝑜𝑑𝑚1
𝑥 ≡ 𝑎2 𝑚𝑜𝑑𝑚2
.
.
.
𝑥 ≡ 𝑎𝑛 𝑚𝑜𝑑𝑚𝑛
• has a unique solution modulo 𝑚 = 𝑚1 𝑚2 … 𝑚𝑛
• i.e. there is only one x such that 0 ≤ x < m
Converse of CRT
• For every x such that 0 ≤ x < m
• where 𝑚 = 𝑚1 𝑚2 … 𝑚𝑛
• and 𝑚1 , 𝑚2 , … , 𝑚𝑛 are pairwise relatively
prime positive integers

• x can be uniquely represented as a n-tuple:


• (x mod 𝑚1 , x mod 𝑚2 , . . . , x mod 𝑚𝑛 )
Example
• Let, 𝑚1 = 5, 𝑚2 = 7, 𝑚3 = 9
• So 𝑚1 , 𝑚2 , 𝑚3 are pairwise relatively prime
• 𝑚 = 5 × 7 × 9 = 315
• So every number x, where 0 ≤ x < 315 can
be represented as:
(𝑥 𝒎𝒐𝒅 5, 𝑥 𝒎𝒐𝒅 7, 𝑥 𝒎𝒐𝒅 9)
• 39 can be written as (4 , 4, 3)
• 11 can be written as (1, 4, 2)
Example
• 𝑚1 = 99, 𝑚2 = 98, 𝑚3 = 97, 𝑚4 = 95
• 𝑚 = 99 × 98 × 97 × 95 = 89403930
• 123684 + 413456 = ?
• 123684 = (33, 8, 9, 89)
• 413456 = (32, 92, 42, 16)

• (33, 8, 9, 89) + (32, 92, 42, 16)


= (65 mod 99, 100 mod 98, 51 mod 97, 105 mod 95)
= (65, 2, 51, 10)
Applications of Congruences
• Hashing Function
• Pseudorandom Numbers
• Check Digits
Cryptography
• Classical Cryptography

• Encrypt: MEET YOU IN THE PARK


• Replace the letters with numbers:
12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10
• Add 3 to each number:
15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13
• Encrypted Message:
PHHW BRX LQ WKHSDUN
• f (p) = (p + 3) mod 26
• This is called encryption
Classical Cryptography

• How to find the original message?


• Determine the inverse function of f
• 𝑓 −1 𝑝 = 𝑝 − 3 𝒎𝒐𝒅 26
• This is called decryption
Classical Cryptography
• Generalization of the Ceaser cipher:
– 𝑓 𝑝 = 𝑝 + 𝑘 𝒎𝒐𝒅 26
– 𝑓 −1 𝑝 = 𝑝 − 𝑘 𝒎𝒐𝒅 26
• This is called the shift cipher

• Further Generalization of the shift cipher:


– f (p) = (ap + b) mod 26
– gcd(a, 26) = 1
• This is called the affine cipher
Classical Cryptography
• How to decrypt affine cipher?
• c = (ap + b) mod 26
• Where gcd(a, 26) = 1
• c ≡ ap + b (mod 26)
• c − b ≡ ap (mod 26)
• There is an inverse 𝑎ത of a modulo 26
ത − b) ≡ 𝑎𝑎𝑝(mod
• 𝑎(c ത 26).
• We know 𝑎𝑎 ത ≡ 1 (mod 26)
• p ≡ a(c − b) (mod 26)
Cryptanalysis
• The process of recovering plaintext from
ciphertext
• Encryption method is unknown
• The key is unknown
Example
• Decrypt the following ciphertext encrypted
using shift cipher:
ECVVNG
• The nine most common letters in English
text:
• E 13%, T 9%, A 8%, O 8%, I 7%, N 7%, S 7%,
H 6%, and R 6%
•E C V V N G
•4 2 21 21 13 6

• If V(21) is the encrypted form of E(4), the


shift is 21 – 4 = 17
• For each integer p, we find
𝑓 −1 𝑝 = 𝑝 − 17 𝒎𝒐𝒅26

• 13 11 4 4 22 15
•N L E E W P
•E C V V N G
•4 2 21 21 13 6

• If V(21) is the encrypted form of T(19), the


shift is 21 – 19 = 2
• For each integer p, we find
𝑓 −1 𝑝 = 𝑝 − 2 𝒎𝒐𝒅26

•2 0 19 19 11 4
•C A T T L E
Two Types of Cipher
• Monoalphabetic or Character Cipher
– Shift Cipher
– Affine Cipher
• Block Cipher
– Transposition Cipher
Example
• Using the transposition cipher based on
the permutation σ of the set {1, 2, 3, 4}
• with σ(1) = 3, σ(2) = 1, σ(3) = 4, and σ(4) = 2

• Encrypt the plaintext message


PIRATE ATTACK
• Divide the text into blocks of 4
PIRA TEAT TACK
• After applying the encryption function:
IAPR ETTA AKTC
Cryptosystems
• A cryptosystem is a five-tuple (P, C,K, E,D)
– P is the set of plaintext strings
– C is the set of ciphertext strings
– K is the keyspace
– E is the set of encryption functions
– Dis the set of decryption functions
Types of Key
• Private Key Cryptography
• Public Key Cryptography

You might also like