Discrete Mathematics 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 – Show that the left hand side of the equation equal to the right hand side, following the laws of associativity and precedence. Example lhs = 2 x (3 + 4) =2x7 = 14 =6+8 =2x3 + 2x4 = rhs Laws of Elementary algebra • Let x, y, c be members of a set A and operation o defined on A. We define the following – o is Reflexive if a o a holds – o is symmetric if when a o b then b o a – o is transitive if when a o b and b o c then a o c • E.g. Equality on integers is reflexive, symmetric, and transitive. Factorisation • Recap of rule of Algebra over ο – For x, y ο ο • x.y = 0 iff x = 0 or y = 0 • Since there is no integer multiplicative inverse for each integer, it is not always possible to find an integer x s.t xd = a, implying a is not always divisible by d – E.g. 3x = 2, 5x = 11, etc. Integer divisibility • Definition – Let a, d ο ο, with d οΉ 0, the integer d divides a written d|a if there exists an integer m s.t a = md – The integer a is a multiple of d and d is a divisor of a when d|a – A divisor is a factor. • Theorem – Let a, d οΉ 0 ο ο. Then the following is true: • d|0 • 1|a • d|d Integer Divisibility • For any integer d, d|d • Proof – d = d.1, – since 1 is an integer, d|d Factorisation in the Integers • Theorem – Let a,b,d and e be integers, with dοΉ0 and e οΉ0. The following are true i. ii. iii. iv. If d|a and d|b, then d|(a+b) If d|a, then d|ab If d|e and e|b then d|b If d|e and e|d then d = e or d = -e – Proof for ii) • d|a, if a = md, m ο ο ο ab = (md)b ο (mb)d ο d|ab since mb is an integer Prime Numbers • Definition – A positive integer π is prime if π has exactly two positive factors – I.e. for all integers r and s, if n = r.s then either r = 1, or s = 1 • The numbers 2, 3, 5 , 7, 11, 13, .. are but just a few of the members in the sequence of primes • Primes are very important numbers… Prime Numbers • Definition – An integer n > 1 is composite if n = r.s for some integers r and s with r οΉ 1 and s οΉ 1. • Example – 10 = 5.2 – 15 = 5.3 – 9 = 3.3 are all composite numbers Prime Numbers • Theorem – Every integer π > 2 has a prime factor • 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 dοΉg 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. ii. iii. iv. v. a+k οΊ b+k(mod n) ak οΊ bk(mod n) ac οΊ bd(mod n) a2 οΊ b2(mod n) 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 ο akοΊbk(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 = 6οΊ1(mod 5) • Example – Solve for x in • x οΊ 3(mod 7) • 7x οΊ 3(mod 5) • 5οΊx(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. • Without the knowledge of the key, (right shift of 3), it is difficult for anyone to decipher this message. – Alice sends this message and Bob will decipher by reversing. – Modular arithmetic is used here. Do you see how? Caesar's Cipher • Caesar’s method – Let ο‘οM, then to get ο’ its ciphered equivalent apply • ο’ = (ο‘+4)(mod 26) – At the receiver, to get the plaintext, apply • ο‘ = (ο’-4)(mod 26) • Note: – -3(mod 26) = 26-3(mod 26) = 23(mod 26) = 23. – To avoid negatives, Bob can use • ο‘ = (26 +ο’-4)(mod 26) Caesar's Cipher • Caesar’s method – Problem • This method is easy to crack • In computer science, a more complex method of encryption employing modular arithmetic is used. • We look at a very simplified version of the RSA encryption algorithm RSA Encryption • Rivest-Shamir-Adleman (RSA) is a public-key crytosystem, used in secure data transmission, attributed to Ron Rivest, Adi Shamir, and Leonard Adleman, who first publicly described the algorithm in 1977. • In transmitting data over networks, it is a good practice to have the data transmission channel secured. RSA Encryption • Operation – To receive a message from Alice, Bob will have to • create his public key and share it with Alice. • Then he will also generate his private key to use to decrypt messages from Alice – These operations are dependent on huge numbers for them to be almost untraceable by a guesser. RSA Encryption • Operation – Bobs public key generation. • • • • • Bob selects 2 very large prime numbers p and q Generates n = p*q Generate the totient ο¦(n) = (p-1)(q-1) Genarate e s.t 1 < e < ο¦(n) , e is coprime with ο¦(n) (e, n) is the public key which he shares with Alice. – Alice’s messege • C(M) = Me(mod n) RSA Encryption • Example – Bobs public key generation. • • • • • Bob selects 2 very large prime numbers p = 11, and q = 7 Generates n = p*q = 11 * 7 = 77 Generate the totient ο¦(n) = (p-1)(q-1) = 10*6 = 60 Genarate e s.t 1 < e < 60, e is coprime with ο¦(n) e = 7 (7, 77) is the public key which he shares with Alice. – Alice’s message • To send D = 4 • C(4) = 47(mod 77) = 60 and sends to Bob RSA Encryption • Example – Decrypting 16. • Bob calculates d s.t deοΊ1(mod ο¦(n)) • (d, n) is Bobs private key. – To decrypt a messge from Alice • M(C) = Cd(mod n) RSA Encryption • Example – Bobs private key generation. • Bob calculates d s.t 7dοΊ1(mod 60) • d = 43 • (43, 77) is Bob’s private key. – To decrypt a message from Alice • M(C) = Cd(mod n) = 6043(mod 77) = 4 Exercise • Alice distributed her public key based on the following values: p = 3, q = 5. She receives message “F” from Bob. Decode this message. Binary Numbers • Binary numbers are numbers composed of digits in base 2 – i.e. in the set {0,1} • Like decimal numbers (base 10), binary numbers are positional numbers. – Each digit in the position of the number has a value of 2 raised to its position, with the leftmost position being a 0 – …2, 1, 0 Binary Numbers • For simplicity we stick to 8 digit binary numbers. • In this case the positional or place values are 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1 Operations on Binary numbers are just like in base 10 but use base 2 Binary Numbers • Find 10112 + 112 Conversions between Binary to Decimal • Decimal to binary – Repeat long division with d = 2 – Reverse the r terms to get the binary representation • E.g. to convert 11 – – – – – 11 = 2.5 + 1 5 = 2.2 + 1 2 = 2.1 + 0 1 = 2.0 + 1 We get 10112 Conversions between Binary to Decimal • Binary to decimal – Add the products of the place values and their respectively placed digits. – E.g. 1012 • 4*1 + 1 = 5 – Points to note • If you have n bits, you have a range from 0 to 2n -1 • E.g. 8 bits has 0 to 255 Binary Numbers • Examples – Convert to decimal • 11111112 • 100000002 • 111011102 – Convert to binary • 191 • 253 Binary Numbers • Data and instructions in computers are stored as binary numbers – BCD, EBCDIC • Machine code are instructions that are executed by machines. Summary • Number theory discusses important topics including – fundamental laws of algebra, – division algorithm – greatest common divisor – modular Arithmetic • We also looked at binary numbers. ???QUESTIONS???