33

PowerPoint PresentationModular arithmetic (clock arithmetic) Modular arithmetic is a system of arithmetic for integers, where values reset to zero and begin to increase again, after

  • Upload
    others

  • View
    79

  • Download
    4

Embed Size (px)

Citation preview

Modular arithmetic (clock arithmetic)Modular arithmetic is a systemof arithmetic for integers, where values reset tozero and begin to increase again, after reachinga certain predefined value, called the modulus(modulo). Modular arithmetic is widely used incomputer science and cryptography.

Euclid's GCD Algorithm

• an efficient way to find the GCD(a,b)

• uses theorem that:

–GCD(a,b) = GCD(b, a mod b)

Euclidean Algorithm

• The Euclidean Algorithm is a technique for quickly finding the GCD of two integers.

• The Algorithm• The Euclidean Algorithm for finding GCD(A,B) is as follows:• If A = 0 then GCD(A,B)=B, since the GCD(0,B)=B, and we can

stop. • If B = 0 then GCD(A,B)=A, since the GCD(A,0)=A, and we can

stop. • Write A in quotient remainder form (A = B⋅Q + R)• Find GCD(B,R) using the Euclidean Algorithm since

GCD(A,B) = GCD(B,R)

• Find the GCD of 270 and 192• A=270, B=192• A ≠0• B ≠0• Use long division to find that 270/192 = 1 with a remainder of 78. We

can write this as: 270 = 192 * 1 +78• Find GCD(192,78), since GCD(270,192)=GCD(192,78)• A=192, B=78• A ≠0• B ≠0• Use long division to find that 192/78 = 2 with a remainder of 36. We

can write this as:• 192 = 78 * 2 + 36• Find GCD(78,36), since GCD(192,78)=GCD(78,36)

• A=78, B=36• A ≠0• B ≠0• Use long division to find that 78/36 = 2 with a remainder of 6. We can

write this as:• 78 = 36 * 2 + 6• Find GCD(36,6), since GCD(78,36)=GCD(36,6)• A=36, B=6• A ≠0• B ≠0• Use long division to find that 36/6 = 6 with a remainder of 0. We can

write this as:• 36 = 6 * 6 + 0• Find GCD(6,0), since GCD(36,6)=GCD(6,0)

• A=6, B=0

• A ≠0

• B =0, GCD(6,0)=6

• So we have shown:

• GCD(270,192) = GCD(192,78) = GCD(78,36) = GCD(36,6) = GCD(6,0) = 6

• GCD(270,192) = 6

• Understanding the Euclidean Algorithm

• If we examine the Euclidean Algorithm we can see that it makes use of the following properties:

• GCD(A,0) = A

• GCD(0,B) = B

• If A = B⋅Q + R and B≠0 then GCD(A,B) = GCD(B,R) where Q is an integer, R is an integer between 0 and B-1

• The first two properties let us find the GCD if either number is 0. The third property lets us take a larger, more difficult to solve problem, and reduce it to a smaller, easier to solve problem.

• The Euclidean Algorithm makes use of these properties by rapidly reducing the problem into easier and easier problems, using the third property, until it is easily solved by using one of the first two properties.

Euclid's GCD Algorithm

• an efficient way to find the GCD(a,b)

• uses theorem that:

–GCD(a,b) = GCD(b, a mod b)

Example GCD(1970,1066)

1970 = 1 x 1066 + 904 gcd(1066, 904)

1066 = 1 x 904 + 162 gcd(904, 162)

904 = 5 x 162 + 94 gcd(162, 94)

162 = 1 x 94 + 68 gcd(94, 68)

94 = 1 x 68 + 26 gcd(68, 26)

68 = 2 x 26 + 16 gcd(26, 16)

26 = 1 x 16 + 10 gcd(16, 10)

16 = 1 x 10 + 6 gcd(10, 6)

10 = 1 x 6 + 4 gcd(6, 4)

6 = 1 x 4 + 2 gcd(4, 2)

4 = 2 x 2 + 0 gcd(2, 0)

• Compute successive instances of GCD(a,b) = GCD(b,a mod b).• Note this MUST always terminate since will eventually get a mod b = 0 (ie

no remainder left).

Prime Numbers

• prime numbers only have divisors of 1 and self

– they cannot be written as a product of other numbers

– note: 1 is prime, but is generally not of interest

• eg. 2,3,5,7 are prime, 4,6,8,9,10 are not

• prime numbers are central to number theory

• list of prime number less than 200 is: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59

61 67 71 73 79 83 89 97 101 103 107 109 113 127

131 137 139 149 151 157 163 167 173 179 181 191

193 197 199

Euler’s Totient function (Φ(n) )• Φ(n) for an input n is count of numbers in {1, 2, 3, …, n}

that are relatively prime to n,• i.e., the numbers whose GCD (Greatest Common Divisor)

with n is 1.• For example, Φ(4) = 2, Φ(3) = 2 and Φ(5) = 4.• If p is a prime numbers,then• Φ(p)= (p-1)

• If p and q are two prime numbers,then• Φ(p*q)= Φ(p)* Φ(q)=(p-1)*(q-1),• If p=6,q=7, then • Φ(6*7)=(6-1)*(7-1)=5*6=30

Multiplicative Inverse

• Two Numbers a and b are saidto be multiplicative inverse ofeach other if

• a*b=1 mod n,where n is themodulo i.e. a.a-1=1 mod n