Integer Division and Modular Arithmetic - Prof. John R. Applin, Study notes of Computer Science

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

Pre 2010

Uploaded on 11/08/2009

koofers-user-4ni
koofers-user-4ni 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
10/6/08&
1&
Integers, Primes, and some
Cryptography
Rosen 3.4, 3.5, 3.7
Integers
Integer Division
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?
Division Theorem
Theorem : Let a, b, and c be integers. 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.
Division Theorem
Corollary : If a, b, and c be integers such
that a | b and a | c, then a | mb + nc
whenever m and n are integers.
Integer division
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
pf3
pf4
pf5

Partial preview of the text

Download Integer Division and Modular Arithmetic - Prof. John R. Applin and more Study notes Computer Science in PDF only on Docsity!

Integers, Primes, and some

Cryptography

Rosen 3.4, 3.5, 3.

Integers

Integer Division

 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?

Division Theorem

Theorem : Let a , b , and c be integers. 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.

Division Theorem

 Corollary : If a , b , and c be integers such

that a | b and a | c , then a | mb + nc

whenever m and n are integers.

Integer division

 The Division Algorithm Let a be an integer and d a positive integer. Then there are unique integers q and r , with 0r < 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 ab (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)

 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

 Example:

17 and 5 are congruent modulo 6

Applications of modular arithmetic: Hash functions

 Hash functions provides fast access to data

of the form (key, value). Common hash

function:

h(k) = k mod m

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…

Example

 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

Greatest Common Divisors

and Least Common Multiples

Greatest Common Divisor (GCD)

 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

Relatively Prime

 Two numbers are relatively prime if they don’t

have any common factors

(other than 1)

 Rephrased: a and b are relatively prime if gcd (a,b) = 1

 gcd (25, 39) = 1,

so 25 and 39 are relatively prime

Least Common Multiple

 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

An Application of Number

Theory: The RSA

Cryptosystem

Ceasar Cipher revisited

 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!

Public key cryptography

 Eliminate the need for securely sending

the encryption key: use a public 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

Public key cryptography

 We use such technology on a daily basis

whenever we visit a secure website

(https:… address)

 RSA encryption (Rivest, Shamir, Adleman)

uses ideas from number theory to make all

that possible.

RSA encryption

The encryption process:

C = Me^ mod n

 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)

RSA decryption

How to decrypt a message:

M = Cd^ mod n

 n = pq, where p,q are prime  d – can be computed knowing e,p,q

 Private key: (d, n)

 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