Chapter4 - Number Theory and Cryptography

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Chapter 4: Number Theory and Cryptography

Nguyen Thi Minh Tam


tamntm16@fe.edu.vn

June 16, 2020


1 4.1 Divisibility and Modular Arithmetic

2 4.2 Integer Representations and Algorithms

3 4.3 Primes and Greatest Common Divisors

4 4.5 Applications of Congruences

5 4.6 Cryptography
4.1 Divisibility and Modular Arithmetic
4.2 Integer Representations and Algorithms
4.3 Primes and Greatest Common Divisors
4.5 Applications of Congruences
4.6 Cryptography

4.1 Divisibility and Modular Arithmetic

If a and b are integers with a 6= 0, we say that a divides b if there


is an integer c such that b = ac. When a divides b we say that
a is a factor or divisor of b,
b is a multiple of a.
Notation:
a | b : a divides b
a 6 | b : a does not divide b

Example 1. Determine whether 3 | 7 and whether 3 | 12.

3/30
Theorem 1
Let a, b, and c be integers, where a 6= 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 6= 0, such that


a | b and a | c, then a | (mb + nc) whenever m and n are integers.
The Division Algorithm
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 .

d is called the divisor, a is called the dividend, q is called the


quotient, and r is called the remainder
q = a div d, r = a mod d

Example 2. What are the quotient and remainder when −11 is


divided by 3?
Modular Arithmetic

If a and b are integers and m is a positive integer, then a is


congruent to b modulo m, denoted by a ≡ b (mod m), if
m | (a − b).
If a and b are not congruent modulo m, we write

a 6≡ b (mod m)

Example 3. Determine whether 17 is congruent to 5 modulo 6


and whether 24 and 14 are congruent modulo 6.
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
i) a + c ≡ b + d (mod m)
ii) ac ≡ bd (mod m)

Corollary 2. Let m be a positive integer and let a and b be


integers. Then
i) (a + b) mod m = ((a mod m) + (b mod m)) mod m
ii) ab mod m = ((a mod m)(b mod m)) mod m
4.1 Divisibility and Modular Arithmetic
4.2 Integer Representations and Algorithms
4.3 Primes and Greatest Common Divisors
4.5 Applications of Congruences
4.6 Cryptography

4.2 Integer Representations and Algorithms

Theorem 1
Let b be an integer greater than 1. Then if n is a positive integer,
it can be expressed uniquely in the form

n = ak b k + ak−1 b k−1 + . . . + a1 b + a0 ,

where k is a nonnegative integer, a0 , a1 , . . . , ak are nonnegative


integers less than b, and ak 6= 0.

The representation of n given in Theorem 1 is called the base b


expansion of n, denoted by (ak ak−1 . . . a1 a0 )b .

9/30
Binary Expansions

Choosing 2 as the base gives binary expansions of integers.


In binary notation each digit is either a 0 or a 1.
Binary expansions (and its variants) are used by computers to
represent and do arithmetic with integers.

Example 4. What is the decimal expansion (the base 10


expansion) of the integer that has (1 0101 1111)2 as its binary
expansion?
Octal and Hexadecimal Expansions

Base 8 expansions are called octal expansions.


Base 16 expansions are hexadecimal expansions.
Sixteen different digits are required for hexadecimal
expansions. Usually, the hexadecimal digits used are 0, 1, 2, 3,
4, 5, 6, 7, 8, 9, A, B, C, D, E, and F, where the letters A
through F represent the digits corresponding to the numbers
10 through 15 (in decimal notation).

Example 5. What is the decimal expansion of the number with


hexadecimal expansion (2AE0B)16 ?
Algorithm 1. Constructing Base b Expansions of n

Example 6. Find the binary expansion of (241)10 .

Example 7. Find the octal expansion of (12345)10 .


Algorithms for Integer Operations

Algorithm 2. Addition of Integers

Example 8. Add a = (1110)2 and b = (1011)2 .


Algorithm 3. Multiplication of Integers

Example 9. Find the product of a = (110)2 and b = (101)2 .


Algorithm 4. Computing div and mod
Modular Exponentiation

bn mod m =?
k−1 +...+a k−1
b n = b ak−1 ·2 1 ·2+a0
= b ak−1 ·2 . . . b a1 ·2 · b a0

Algorithm 5. Modular Exponentiation

Example 10. When using the modular exponentiation algorithm


to compute 66 mod 13, What are the remainders computed by
successively squaring?
4.1 Divisibility and Modular Arithmetic
4.2 Integer Representations and Algorithms
4.3 Primes and Greatest Common Divisors
4.5 Applications of Congruences
4.6 Cryptography

4.3 Primes and Greatest Common Divisors

Primes, Composites
An integer p greater than 1 is called prime if the only positive
factors of p are 1 and p.
An integer that is greater than 1 and is not prime is called
composite.

17/30
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 nondecreasing size.

Example 11. Find the prime factorization of each of these


integers.
a) 729
b) 1001
Theorem 2
If n is a composite integer, then n has a prime divisor less than or

equal to n.

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.

Note: The odds that a randomly selected positive integer less


than n is prime are approximately (n/ ln n)/n = 1/ ln n.
Conjectures and Open Problems About Primes

f (n) = n2 − n + 41 is prime for all positive integers n ≤ 40


=⇒ conjecture: f (n) is prime for all positive integers n.

This conjecture is false.


Goldbach’s Conjecture every even integer n, n > 2, is the sum
of two primes.
The Twin Prime Conjecture there are infinitely many twin
primes (twin primes are pairs of primes that differ by 2).
Greatest Common Divisors and Least Common Multiples

Greatest Common Divisors


Let a and b be integers, not both zero. The greatest common
divisor of a and b, denoted by gcd(a, b), is the largest integer d
such that d|a and d|b.

Example 12. What is the greatest common divisor of 120 and 500.
Greatest Common Divisors and Least Common Multiples

Greatest Common Divisors


Let a and b be integers, not both zero. The greatest common
divisor of a and b, denoted by gcd(a, b), is the largest integer d
such that d|a and d|b.

Example 12. What is the greatest common divisor of 120 and 500.
Solution:

120 = 23 31 51
500 = 22 53
⇒ gcd(120, 500) = 22 51 = 20
Relatively Prime
The integers a and b are relatively prime if their greatest
common divisor is 1.
The integers a1 , a2 , . . . , an are pairwise relatively prime if
gcd(ai , aj ) = 1 whenever 1 ≤ i < j ≤ n.

Example 13.
gcd(17, 22) = 1 ⇒ 17 and 22 are relatively prime.
7, 10, 11, 17, 23 are pairwise relatively prime.
Least Common Multiples
The least common multiple of the positive integers a and b,
denoted by lcm(a, b), is the smallest positive integer that is
divisible by both a and b.

Example 14.
What is the least common multiple of m = 75 1112 1390 and
n = 24 73 1114 ?

Theorem 5
ab = gcd(a, b) · lcm(a, b)
The Euclidean Algorithm.

Lemma
Let a = bq + r , where a, b, q, and r are integers. Then
gcd(a, b) = gcd(b, r ).

Example 15. Find the greatest common divisor of 252 and 198
using the Euclidean algorithm.
4.1 Divisibility and Modular Arithmetic
4.2 Integer Representations and Algorithms
4.3 Primes and Greatest Common Divisors
4.5 Applications of Congruences
4.6 Cryptography

4.5 Applications of Congruences

Hashing Functions
A hashing function h assigns memory location h(k) to the
record that has k as its key.
One of the most common is the function

h(k) = k mod m

where m is the number of available memory locations.

Example 16. Find the memory locations assigned by the hashing


function h(k) = k mod 111 to the records of customers with
Social Security numbers 064212848 and 037149212.

26/30
Pseudorandom Numbers
xn+1 = (axn + c) mod m
where

a : multiplier, 2 ≤ a < m
c : increment, 0 ≤ c < m
x0 : seed, 0 ≤ x0 < m.

Example 17. A sequence of pseudorandom numbers is generated


as follows

x0 = 4, xi = (6xi–1 + 5) mod 13 if i > 0

Find x6 .
4.1 Divisibility and Modular Arithmetic
4.2 Integer Representations and Algorithms
4.3 Primes and Greatest Common Divisors
4.5 Applications of Congruences
4.6 Cryptography

Classical Cryptography
Number theory is the basis of many classical ciphers. These
ciphers encrypt messages by changing each letter to a
different letter.
Replace each letter by an integer from 0 to 25 (replace A by
0, K by 10, and Z by 25).
In the encrypted version of the message, the letter represented
by p is replaced with the letter represented by

f (p) = (p + k) mod 26.

Such a cipher is called a shift cipher.


Decryption can be carried out using

f −1 (p) = (p − k) mod 26.

28/30
Example 18. Encrypt the message “ATTACK” using the shift
cipher with shift k = 5.

Example 19. Decrypt the message ”EOXH MHDQV” that were


encrypted using the Caesar cipher (shift cipher with shift k = 3) .
Exercises

You might also like