Professional Documents
Culture Documents
Number Theory
Reading
• Barnier & Chan
– Chapter 6
Outline
• Laws of elementary algebra
• Factorisation in the Integers
• Greatest common divisor
• Modular Arithmetic and Binary Numbers
• Applications: Cryptography
• Note; s.t stands for ‘such that’
Introduction
• Digital computers store information and data
as computer words, which are composed of
strings of 0’s and 1’s
• As a computer scientist knowledge of the
arithmetic of binary numbers is essential
• We start by looking at decimal numbers since
they have a lot in common with binary
numbers
Elementary Algebra
• Number theory is a vast and fascinating field
of mathematics, consisting
– properties of whole numbers.
– Primes and prime factorization
– functions such as the divisor function
– modular arithmetic.
Elementary Algebra
• Definition
– A set 𝑨 has closure (or is closed) under an
operation ( ) if performance of that operation on
members of the set 𝑨 always produces a member
of the set 𝑨. I.e. if 𝑎,𝑏 𝐴 , then 𝑎 𝑏 𝐴
• The set of integers is closed under addition,
subtraction and multiplication but not under
division.
Laws of Elementary Algebra
Example
• Show that the following equations hold.
– 2 x (3 + 4) = 2x3 + 2x4
– 4 x(6 x 2) = (4 x 6) x 2
• Theorem
– Every number is either a prime or a product of primes.
• Definition
– Two integers a and b are said to be coprime or
relatively prime to each other if the two numbers
have no common factors other than 1
Division Algorithm for
• Algorithm
– Let a and d be integers, with d 0. There exist
unique integers q and r such that
– a = qd + r and 0 r |d|
• E.g.
– For a = 20 and d = 7, q = 2 and r = 6
– I.e. 20 = 2.7 + 6
• When r = 0, d|a otherwise we say that d does
not divide a
Division Algorithm for Z
• Ex:
– Let 𝑑 and 𝑘 be positive integers. Suppose 𝑞 is the
quotient and r is the remainder when 𝑎 is divided
by 𝑑. Prove that 𝑞 is the quotient and 𝑘𝑟 is the
remainder when 𝑘𝑎 is divided by 𝑘𝑑.
The Greatest Common Divisor
• Definition
– Given two integers a and b, the greatest common
divisor of a and b denoted by 𝑔𝑐𝑑(𝑎,𝑏) is the
greatest number which divides 𝑎 and 𝑏.
– In other words, the gcd is the greatest factor of
both 𝑎 and 𝑏.
• For example, let 𝑎 = 12 and 𝑏 = 20 then gcd(20,12) = 4
• F(20) = {1,2,4,5,10,20}
• F(12) = {1,2,3,4,12} and 4 is the greatest in the
intersection
The Greatest Common Divisor
• If g is the greatest common divisor of a and b
then
– g|a and g|b
– If any other number dg is s.t d|a and d|b then
d|g as well
• If a > b then
– b = gcd(a,b) if b|a and
– Gcd(a,b) = gcd(b, a-b) if b does not divide a
Greatest Common Divisor
• Example
– Find gcd of
• a = 15, b = 7
• a = 8, b= 64
• a = 6, b = 9
• If a < b then the gcd(a, b) = gcd(b,a)
Greatest Common Divisor
• Theorem: Euclidean method
– Let a and d be integers with a = qd + r, then
• gcd(a,d) = gcd(d,r)
– We will not provide proof for this theorem
• This theorem provides a mechanism for
iteratively finding the gcd of a and d using
long division.
• The 𝑔𝑐𝑑 is the remainder just before the zero
remainder
Greatest Common Divisor
• Example
• gcd(9,3) = 3, since 3|9
• gcd(15, 9), we apply long division as follows
– 15 = 9.1 + 6
– 9 = 6.1 + 3
– 6 = 3.2 + 0
• The r just before 0 is the gcd i.e. 3
Greatest Common Divisor
• Theorem
– If g is the gcd of a and b, then there exists integers
m and n such that 𝑎𝑚 + 𝑏𝑛 = 𝑔
– We provide no truth
• The values m and n are obtained by reversing
the long division method of deriving the gcd
of a and b
Greatest Common Divisor
• Example:
– Find m and n for the given a and b s.t am + bn = g
– a = 15, b = 9
• Solution
– We just saw that
– 15 = 9.1 + 6…(i)
– 9 = 6.1 + 3…(ii)
– 6 = 3.2 + 0
Greatest Common Divisor
▪ 15 = 9.1 + 6…(i)
▪ 9 = 6.1 + 3…(ii)
▪ 6 = 3.2 + 0
3 = 9 – 6.1, from (ii)
3 = 9 – (15 – 9.1).1 from (i)
3 = 9 -15.1 + 9.1
3 = 9.2 – 15.1
3 = -15.1 +9.2,
m = -1 and n = 2
Greatest Common Divisor
• Definition
– Two integers a and p, with p being prime number.
Then p is relatively prime to a if the gcd(a, b) = 1
• Example
– The following pairs of a and b are relatively prime
– a = 10, b = 7
– a = 10, b = 7
– a = 9, b = 8
Modular Arithmetic
• Definition
– Let a, b and n be integers with n > 0. Then a is said to
be congruent to b modulo n denoted by a
b(mod n) if n leaves the same remainder when divided
by a and by b.
– I.e. a%n = b%n
– Equivalently the difference of a and b is divisible by n
or a – b = nk, for some integer k.
• E.g.
– 8 5 (mod 3)
Modular Arithmetic
• Mod operator
– The domain of a(mod n) is the set of integers {0, 1,
2, .., n-1} regardless of the value of a.
– 8(mod 3) = 2
– 8(mod 9) = 8
– 21(mod 5) = 0 etc
– 82(mod 9) = ??
– 1023(mod 2) = ??
Modular Arithmetic
• Theorem
– Let a, b, c, d and n be integers such that n >0, and
that a b(mod n), c d(mod n), then
i. a+k b+k(mod n)
ii. ak bk(mod n)
iii. ac bd(mod n)
iv. a2 b2(mod n)
v. ap bp(mod n) for any integer p = 1, 2, 3,….
• We show proof for (i) and (iv)
Modular Arithmetic
• Let a b(mod n), show that ak bk(mod n) for any
integer k
• Proof
Premise:
a b(mod n),….(i)
b – a = nr, for an integer r…(ii)
bk – ak
= (b – a)k
= (nr)k, from (ii)
= n(rk),
= ns, where s = rk is an integer
akbk(mod n)
Modular Arithmetic
• Definition
– If a.b 1(mod n) then b is said to be an inverse of
a modulo n.
– E.g. 3 is inverse of 2 mod 5 since
3.2 = 61(mod 5)
• Example
– Solve for x in
• x 3(mod 7)
• 7x 3(mod 5)
• 5x(mod 7)
Modular Arithmetic
• Theorem
– 𝑎𝑏 𝑚𝑜𝑑 𝑛 = [(𝑎(𝑚𝑜𝑑 𝑛)(𝑏 (𝑚𝑜𝑑 𝑛)](𝑚𝑜𝑑 𝑛)
– This theorem is used to simplify expressions, involving
really large numbers, without the need of knowing
their exact values
• E.g.
55.26(mod 4)
=(55(mod 4).26(mod 4))(mod 4)
=(1.3)(mod 4)
= 3(mod 4)
=4
Modular Arithmetic
• Example
– Find 355(mod 8)
– Solution
• Note 32 1(mod 8)
• 355 = [32]27 .3
• 355(mod 8)
127.3(mod 8)
3(mod 8)
=3
Modular Arithmetic
• Example:
• What is the last digit of 355?
– Solution
• Find 355(mod 10)
Modular Arithmetic: Applications
• Say Ann wishes to send Bob a message M.
• Danger is, a third party might intercept the
message and do whatever they wish with it.
• Solution
– encrypt the message M to C.
– Share the encryption key with receiver.
– Then send encrypted message C to receiver
– Receiver decrypts by reversing the encryption
procedure.
Cryptology
• Cryptology = cryptography + cryptanalysis
• Cryptology is the science of ciphering data or
messages (cryptography) and deciphering the
encrypted messages (cryptanalysis).
Caesar's Cipher
• Caesar’s method
– Shift the positions of the alphabetical letters by a
known step (key) E.g. a right shift of 3, the letter D
would be replaced by G, E would become H, and
so on. In this convention it implies that a new
alphabet is created as follows:
Caesar's Cipher
• Caesar’s method
– Use the ciphertext to generate message e.g.