



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concepts of integer division, division theorem, and modular arithmetic. It explains the division algorithm, the concept of congruence modulo m, and its applications in hash functions and pseudorandom numbers. It also discusses the ceasar cipher and prime numbers.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Rosen 3.4, 3.5, 3.
If a and b are integers with a ≠ 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 of b and b is a multiple of a. The notation a | b denotes that a divides b. Examples: Does 5 | 10? Does 5 | 15? Does 2 | 5?
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 , q is called the quotient , q = a div d r is called the remainder. r = a mod d (a % d in Java) Examples 101 = 11 * 9 + 2. 101 = 11 * 8 + 13? -11 = 3 (-4) + 1. -11 = 3 (-3) – 2
Integer division Examples : Given a = 13 and d = 4 , what are the values of q and r? Since 13/4 = 3 + 1/4 , we know that q = 13 div 4 = 3 and r = 13 mod 4 = 1. Given a = 96 and d = 15 , what are the values of q and r? Since 97/15 = 6 + 7/15 , we know that q = 97 div 15 = 6 and r = 97 mod 15 = 7 Modular Arithemetic 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 Notation: a ≡ b (mod m ) Example: Is 17 congruent to 5 modulo 6? As 6 divides 17-5, they are congruent Example: Is 24 congruent to 14 modulo 6? As 6 does not divide 24-14 = 10, they are not congruent distinguish between b (mod m) and b mod m Modular Arithmetic (cont) Theorem : 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 a % m = b % m (in Java notation) Example: Is 17 congruent to 5 modulo 6? Rephrased: does 17 ≡ 5 (mod 6)? 17 mod 6 = 5 mod 6 Example: Is 24 congruent to 14 modulo 6? Rephrased: 24 ≡ 14 (mod 6) 24 mod 6 ≠ 14 mod 6 Modular Arithmetic (cont)
Applications of modular arithmetic: Hash functions
image from http://en.wikipedia.org/wiki/Image:HASHTB08.svg Pseudorandom Numbers A linear congruential methods uses the following rule: xn+1 = (a xn + c) mod m m – modulus a – multiplier c – increment x 0 – seed Example: m=9, a=7, c=4, x 0 =3 generates 3,7,8,6,1,2,0,4,5,3,7,8,6,1,2,0,4,5,3…
Is 899 prime or composite? Solution Divide 899 by successively larger primes < √899 , starting with 2 We find that 29 and 31 divide 899 FUN FACT: On a unix system, enter “factor 899”
factor 899 899: 29 31
The greatest common divisor of two integers a and b is the largest integer d such that d | a and d | b Denoted by gcd(a,b) Examples gcd (24, 36) = 12 gcd (17, 22) = 1 gcd (100, 17) = 1 Easy way to find gcd: Find all positive common divisors of both integers then take the largest
Rephrased: a and b are relatively prime if gcd (a,b) = 1
The least common multiple of the positive integers a and b is the smallest positive integer that is divisible by both a and b. Denoted by lcm ( a , b ) Example: lcm(10, 25) = 50 What is lcm (95256, 432)? 95256 = 2^33572 , 432=2^433 lcm (2^33572 , 2^433 ) = 2max(3,4) 3 max(5,3) 7 max(2,0)^ = 2^43572 = 190512 And in general: Theorem: Let a and b be positive integers. Then ab = gcd(a,b) * lcm(a,b) Example: gcd (10,25) = 5, lcm (10,25) = 50 1025 = 5
You encrypt using c = (p + k) mod 26 k is the encryption key and decrypt by shifting by -k: p = (c – k ) mod 26 i.e. -k is the decryption key If you know the encryption key you know the decryption key Problem: Need a safe way to send the encryption key!
I generate public and private keys I publish my public key You encode a message into numbers and encrypt them Only I, who know the private key, can decrypt it
M – integer representing the plaintext C – the encrypted message n – a product of two large prime numbers p,q e – a number which is relatively prime to (p-1)(q-1) Public key: (e, n)
n = pq, where p,q are prime d – can be computed knowing e,p,q
If you could factor n you could find out the private key! But it turns out that it’s practically impossible to factor very large numbers