29
The Integers and Division 1.Division 2.Modular Arithmetic. We will review the basic concept of number theory

The Integers and Division

Embed Size (px)

DESCRIPTION

The Integers and Division. We will review the basic concept of number theory. Division Modular Arithmetic. Division. Definition: If a and b are integers with a ≠ 0,we say that a divides b if there is an integer c such that b = a c. - PowerPoint PPT Presentation

Citation preview

Page 1: The Integers and  Division

The Integers and Division

1.Division

2.Modular Arithmetic.

We will review the basic concept of number theory

Page 2: The Integers and  Division

Definition: If a and b are integers with a ≠ 0,we say thata divides b if there is an integer c such that b = a c.

In this case (when a divides b), we say that:

• a is a factor of b.

• b is multiple of a.

• b is dividable by a.

We use the notations (when a divides b):

a | b (a divides b)

a ∤ b (a does not divide b)

Division

Page 3: The Integers and  Division

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

• For 3 | 7:

3 divides 7 if 7= c* 3 What is the value of c?

if c=1 7 = 1 *3=3 (invalid)

if c=2 7 = 2 *3= 6 (invalid)

if c=3 7 = 3 *3=9 (invalid)

Therefore, 3 7 (3 does not divides 7), because 7/3 is not ∤an integer.

• For 3 | 12:

3 divides 12 if 12= c* 3 What is the value of c?

we can take c=4 (12= 4 * 3)

Therefore, 3 | 12

Page 4: The Integers and  Division

Home work # 1: Does 17 divide each of these numbers?

a) 68

b) 84

c) 357

d) 1001

You can send the home work to the following address:[email protected]

You must write the following :)1 (Name (2) ID (3) Course code

Page 5: The Integers and  Division

Theorem: Let a be an integer and d a positive integer.Then there are unique integers q and r with 0 ≤ r < dsuch that a = d q + r.

In this case, we called that:

• d is the divisor

• a is the dividend

• q is the quotient and equals q = a div d.

• r is the reminder and equals r = a mod d.

Page 6: The Integers and  Division

Example : Given a = 7 and d= 3. Find the quotient and reminder.

a = d q +r

7 = 3 q + r

q=2 and r =1

7= 3 ∙ 2 + 1

Remarks:

q=2 is a unique integer. Can you put another value for q?

r =1 satisfies 0 ≤ r < d.

7 Div 3= 2

7 Mod 3=1

Page 7: The Integers and  Division

Example : what are the quotient and reminder when -11 is divided by 3?

Sol: a = -11 and d= 3

a = q ∙ d +r and 0 ≤ r < d=3

-11= q ∙ 3 + r

q= -4

r= 1

Remark : in the above example a= -11 and d= 3

If we put q=-3 then -11= (-3) ∙ 3 + r

Therefore, r= -2

Invalid solution

Because r must satisfies 0 ≤ r < d=3

Remark: the reminder cannot be negative.

Page 8: The Integers and  Division

Definition: 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.

We use the notations :

a ≡ b (mod m) (a is congruent to b modulo m)

a ≢ b (mod m) (a and b are not congruent to modulo m)

Modular arithmetic

Page 9: The Integers and  Division

Example :

Determine whether 17 is congruent to 5 modulo 6.

Sol: a=17, b=5 and m=6

We want to prove m divides a-b

a-b= 17-5=12

m =6 divides a-b=12 17 ≡ 5 (mod 6).

Example :

Determine whether 24 is congruent to 14 modulo 6.

Page 10: The Integers and  Division

Randomly chosen numbers are often needed for computer simulations.

Application: Pseudorandom Numbers

The most commonly used procedure for generating pseudorandom numbers is the linear congruential method.

Page 11: The Integers and  Division

Application: Pseudorandom Numbers

Congruential Method:

(1) Choose four integers: • modulus m• multiplier a• increment c• seed x0.

where 2 ≤ a < m, 0 ≤ c < m, and 0 ≤ x0 < m.

(2) We generate the sequence of pseudorandom {xn}, with 0 ≤ x0 < m for all n by successively using the congruence

xn+1 = (a xn + c) mod m

Page 12: The Integers and  Division

Example: Generate the sequence of pseudorandom numbers by choosing m = 9, a = 7, c =4, and x0= 3.

Solution: by using xn+1 = (a xn + c) mod mn=0: x1 = (a x0 + c) mod 9

) = 7 * 3 + 4 (mod 9 = 25 mod 9

x1 = 7 n=1: x2 = (a x1 + c) mod 9

) = 7 * 7 + 4 (mod 9 = 53 mod 9

x2 = 8 n=2: x3 = (a x2 + c) mod 9

) = 7 * 8 + 4 (mod 9 = 60 mod 9

x3 = 6

Page 13: The Integers and  Division

Solution: by using xn+1 = (a xn + c) mod m

n xn Xn+1= (a xn + c) mod m

0 3 X1= (7*3 + 4) mod 9 = 7

1 7 X2= (7*7 + 4) mod 9 = 8

2 8 X3= (7*8 + 4) mod 9 = 6

3 6 X4= (7*6 + 4) mod 9 = 1

4 1 X5= (7*1 + 4) mod 9 = 2

5 2 X6= (7*2 + 4) mod 9 = 0

6 0 X7= (7*0 + 4) mod 9 = 4

7 4 X8= (7*4 + 4) mod 9 = 5

8 5 X6= (7*5 + 4) mod 9 = 4

Page 14: The Integers and  Division

Application: Cryptology

One of the important applications of congruence is cryptology.

Cryptology is the study of secret messages.

Shift Cipher Method:

Main idea: the letter represented by integer p is replaced with the letter represented by (p+k) mod 26 and k is an integer.

(1) Replace each letter by an integer from 0 to 25, based on its position in the alphabet.

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Page 15: The Integers and  Division
Page 16: The Integers and  Division

Application: Cryptology

(2) Apply the function, f, on the integer p as follows:

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

Example: if p =3 and k=3 then f(p =3)= (3+3) mod 26

= 6

if p =24 and k=3 then f(p=24)= (24+3) mod 26

= 1

(3) Translate the integer to letter according to previous table of alphabetic.

Page 17: The Integers and  Division

Example: Use Caesar’s method to encrypt the following message “MEET YOU IN THE PARK.”

Solution:

)1 (Replace the letters in the message with the numbers as follows:

)2 (Replace each number , p, by f(p)= (p+3) mod 26.

M E E T Y O U I N T H E P A R K

12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10

12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10

15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13

Page 18: The Integers and  Division

)3 (Translate the integers to letters as follows:

Therefore, the produce encrypted message is “PHHW BRX LQ WKH SDUN”

15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13

P H H W B R X L Q W K H S D U N

A B C D E F … Z

0 1 2 3 4 5 … 25

Page 19: The Integers and  Division

# To recover the original message from a secret message encrypted by shift cipher, we use the function f -1 (the inverse of f).

f -1(p)=(p-k) mod 26

This means that : to find an original message, each letter is shifted back k letters in the alphabet.

# In case of k=3 (caesar cipher), each letter is shifted back 3 letters in the alphabet.f -1(p)=(p-3) mod 26

Decryption

Page 20: The Integers and  Division

Example: Use Caesar’s method to decrypt the following message “PHHW BRX LQ WKH SDUN.”

Solution:

)1 (Replace the letters in the message with the numbers as follows:

)2 (Replace each number , p, by f -1(p)= (p-3) mod 26.

15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13

12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10

P H H W B R X L Q W K H S D U N

15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13

Page 21: The Integers and  Division

)3 (Translate the integers to letters as follows:

Therefore, the produce decrypted message is “Meet you in the park”

12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10

M E E T Y O U I N T H E P A R K

A B C D E F … Z

0 1 2 3 4 5 … 25

Page 22: The Integers and  Division

Another encryption method is .

Affine transformation:

Main idea: the letter represented by integer p is replaced with the letter represented by (a p+b) mod 26 and a and b are integers.

Page 23: The Integers and  Division

Example: Encrypt the following message “” WELCOME TO HAIL” using f(p)= (3 p+7) mod 26Solution:

)1 (Replace the letters in the message with the numbers as follows:

)2 (Replace each number , p, by f(p)= (3 p +7) mod 26.

W E L C O M E T O H A I L

22 4 11 2 14 12 4 16 14 7 0 8 11

22 4 11 2 14 12 4 16 14 7 0 8 11

21 19 14 13 23 17 19 12 23 2 7 5 14

Page 24: The Integers and  Division

)3 (Translate the integers to letters as follows:

Therefore, the produce encrypted message is “VTONXRT MX CHFO”

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Page 25: The Integers and  Division

Application: Hashing Functions

One of the important applications of congruence is assign memory locations to computer files.

How can memory locations be assigned so that customer records can be retrieved quickly?

Hashing Function:

Main idea: a hashing function h assigns memory location h(k) to record that has k as its key.

h(k)= k mod m

Where m is the number of available memory locations.

Page 26: The Integers and  Division

Example: assume that m=11 and the k=064212848.ThenH(064212848)=064212848 mod 11=7

Page 27: The Integers and  Division

Homework on Integers and Division

Page 28: The Integers and  Division

(1) Does 17 divide each of these numbers?

a) 68 b) 84 c) 357 d) 1001

(2) What are the quotient and reminder when

a) 19 is divided by 77 ? b) -111 is divided by 11?

c) -1 is divided by 3? d) 4 is divided by 1?

(3) Evaluate these quantities

a) -17 mod 2 b) 144 mod 7

c) -94 mod 11 d) 155 mod 19

(4) Decide whether each of these integers is congruent to 5 modulo 17?

a) 80 b) 103 c) -29 d) -122

Page 29: The Integers and  Division

(5) What sequence of pseudorandom numbers is generated using linear congruential number generator xn+1= 3 xn mod 11 with seed x0=2?

(6) What sequence of pseudorandom numbers is generated using linear congruential number generator xn+1= (4 xn +1) mod 7 with seed x0=3?

(7) Encrypt the message “Do NOT PASS GO” by using the following encryption functions:

a) f(p) = (p+3) mod 26 (The Caesar cipher)

b) f(p) = (p+13) mod 26

c) f(p) = (3p+7) mod 26

(8) Decrypt these messages using f -1(p)= (p-3) mod 26

a) EOXH MHDQV b) WHVW WRGDB c) HDW GLP VXP