0% found this document useful (0 votes)
16 views83 pages

Modular Arithmetic Guide

Uploaded by

Ragavendra Rahul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views83 pages

Modular Arithmetic Guide

Uploaded by

Ragavendra Rahul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CSI3022 – Cyber Security and Application

Security

1
Modular Arithmetic

2
Modular Arithmetic
• Finding mod of positive number
• Finding mod of negative number
• Congruence property
• Modular arithmetic operations
• Modular exponentiation
• Finding mod using Fermat’s Theorem
• Finding mod using Euler’s Theorem
• Finding mod using Chinese remainder Theorem

3
Modular Arithmetic

4
Modular Arithmetic

5
Modular Arithmetic

6
Example

• 18 mod 12 = ?

7
Example
• 18 mod 12 =?

18=q12+r
Find q*12 <=18
So choose q=1
q+1*12>18
18=1*12 + r
18=1*12 + r
=12+r , 12<=18
=12+r , 12<=18
18-12=r
18=2*12 + r
6=r , 0<=6<12
=24+r , 24>18
Ans: 18 mod 12 = 6 8
1024 mod 18=?

9
Example
• 1024 mod 18=?

1024=q18+r
Find q*18 <=1024
q+1*18>1024 So choose q=56
1024=56*18 + r 1024=56*18 + r
=1008+r , 1008<=1024 =1008+r , 1008<=1024
1024=57*18 + r 1024-1008 = r
=1026+r , 1026>1024 16=r , 0<=16<18
yes Ans: 1024 mod 18 = 16

10
Exercise

• 18 mod 12 = ?
• 24 mod 12 = ?
• 32 mod 12 = ?
• 4 mod 12 = ?
• 8 mod 12 = ?
• 1024 mod 18 =?

11
Exercise - Ans

• 18 mod 12 = 6
• 24 mod 12 = 0
• 32 mod 12 = 8
• 4 mod 12 = 4
• 8 mod 12 = 8
• 1024 mod 18 =16

12
-7 mod 5 = ?

13
Modular Arithmetic
• For negative numbers
-7 mod 5=?
Solution: To find -7 mod 5, we firstly find the largest number that is
less than or equal to -7 and divisible by 5. That number is -10. Now,
in order to get remainder subtract -10 from -7, which gives 3 that is
the remainder.
• Remainder can also be computed from the above definition. Since,
remainder is least positive integer that should be subtracted from
dividend to make it divisible by divisor. Thus the least positive
integer that should be subtracted from -7 to make it divisible by 5
is 3.
Hence the remainder comes out to be 3.

14
Modular Arithmetic
Division algorithm

15
Modular Arithmetic

Finding mod
-6 mod 5=?

16
Example
• -6 mod 5=?

-6=q5+r
Find q*5 <=-6
q+1*5>-6 So choose q=-2
Number should be > -6. So next -6=(-2)*5 + r
number is -10 =-10+r , -10<=-6
-6=(-2)*5 + r -6-(-10) = r
=-10+r , -10<=-6 -6+10 =r
1024=-1*5 + r 4=r , 0<=4<5
=-5+r , -5>-6 Ans: -6 mod 5 = 4
yes
17
Exercise

• -23 mod 3 =?
• -79 mod 5 =?
• -173 mod 7=?

18
Exercise - Ans

• -23 mod 3 = 1
• -79 mod 5 = 1
• -173 mod 7 = 2

19
-132 mod 8=?

20
-132 mod 8=4

21
Modular Arithmetic
• Finding mod of positive number
• Finding mod of negative number
• Congruence property
• Modular arithmetic operations
• Modular exponentiation
• Finding mod using Fermat’s Theorem
• Finding mod using Euler’s Theorem
• Finding mod using Chinese remainder Theorem

22
Properties of Congruences

23
Properties of Congruences

24
Modular Arithmetic

25
Modular Arithmetic

26
Modular Arithmetic
Properties of Congruences

27
Modular Arithmetic
Properties of Congruences

28
Modular Arithmetic

23 ≡ 3 mod 5
3 ≡ 58 mod 5

23 ≡ 58 mod 5

29
Modular Arithmetic
a=23
b=3
c=58
n=5
23 ≡ 3 mod 5
23 ≡ 3 mod 5
3 ≡ 58 mod 5
3 mod 5=3
23 mod 5 =3
3 ≡ 58 mod 5 23 ≡ 58 mod 5
58 mod 5 = 3
3 mod 5 = 3
23 ≡ 58 mod 5
58 mod 5=3
23 mod 5 =3
30
Modular Arithmetic

23 = 8 mod 5
a=b mod n
Property n|(a-b)

a-b= 23-8
= 15
5|15
Hence proved
31
Modular Arithmetic

-11 = 5 mod 8
a=b mod n
Property n|(a-b)

a-b= -11-5
= -16
8|-16
Hence proved
32
Modular Arithmetic

81= 0 mod 27
a=b mod n
Property n|(a-b)

a-b= 81-0
= 81
27|81
Hence proved
33
Modular Arithmetic

23 = 8 mod 5 -11 = 5 mod 8 81= 0 mod 27


a=b mod n a=b mod n a=b mod n
Property n|(a-b) Property n|(a-b) Property n|(a-b)

a-b= 23-8 a-b= -11-5 a-b= 81-0


= 15 = -16 = 81
5|15 8|-16 81|27
Hence proved Hence proved Hence proved
34
Modular Arithmetic

35
Modular Arithmetic

36
Modular Arithmetic

73 = 4 mod 23
= 4%23
=4

4=73 mod 23
= 73%23
=4

Therefore
73 = 4 mod 23

4=73 mod 23 37
Modular Arithmetic

21 = -9 mod 10 21 = -9 mod 10
= -9%10 = -9%10
=1
-9%10
-9=21 mod 10 a=qn+r
= 21%10 -9 = q10+r
=1 -9 = (-1)*10 + r
-9 = -10+r , -10<=-9
Therefore -9+10=r
21 = -9 mod 10 1=r
r=1 , 0<=r<10

-9=21 mod 10
38
Modular Arithmetic

73 = 4 mod 23 21 = -9 mod 10 21 = -9 mod 10


= 4%23 = -9%10 = -9%10
=4 =1
-9%10
4=73 mod 23 -9=21 mod 10 a=qn+r
= 73%23 = 21%10 -9 = q10+r
=4 =1 -9 = (-1)*10 + r
-9 = -10+r , -10<=-9
Therefore Therefore -9+10=r
73 = 4 mod 23 21 = -9 mod 10 1=r
r=1 , 0<=r<10

4=73 mod 23 -9=21 mod 10


39
Modular Arithmetic

a=23
b=3
c=58
n=5

23 = 3 mod 5
=3
3 = 58 mod 5
=3
23 = 58 mod 5
=3 40
Modular Arithmetic Operations

41
Modular Arithmetic
Modular Arithmetic Operations

42
Modular Arithmetic

Proofs of modular arithmetic properties

43
Modular Arithmetic

find the largest number that is less than or equal


to -4 and divisible by 8
Proofs of modular arithmetic properties That is -8
So
-4=-8+r
-4+8=r
4=r
44
r=4
For Practice…

45
Modular Arithmetic
• Which of the following are true?
7 ≡ 1 (mod 3)
7 ≡ 3 (mod 3)
7 ≡ 147 (mod 3)
76 ≡ −152 (mod 3)

46
Modular Arithmetic
• Which of the following are true?
7 ≡ 1 (mod 3)
7 ≡ 3 (mod 3)
7 ≡ 147 (mod 3)
76 ≡ −152 (mod 3)
Answer 
7 ≡ 1 (mod 3)
76 ≡ −152 (mod 3)

47
Modular Arithmetic
• Given that 5x ≡ 6 (mod 8), find x.

48
Modular Arithmetic
• Given that 5x ≡ 6 (mod 8), find x.
6 mod 8 =? 5(1)-6=-1
5(2)-6=4
=6 5(3)-6=9
5x mod 8 =? 5(4)-6=14
5(5)-6=19
5x=8q+r 5(6)-6=24
5x=8q+6 24 is multiple of 8
So x is 6
5x-6=8q 5x mod 8 =?
5x-6 should be a multiple of 8 5(6) mod 8
=30 mod 8
=6
49
Modular Arithmetic
• Given that 5x ≡ 6 (mod 8), find x.

Ans: x=6

50
Modular Arithmetic
If x ≡ 5 (mod 8) and y ≡ 6 (mod 8),
What number is x+y congruent to modulo 8?

51
Modular Arithmetic
If x ≡ 5 (mod 8) and y ≡ 6 (mod 8),
What number is x+y congruent to modulo 8?

Ans: 3

52
Modular Arithmetic
• Find the least positive value of x such that.
(i) 71 ≡ x (mod 8)
(ii) 78 + x ≡ 3 (mod 5)
(iii) 89 ≡ (x + 3) (mod 4)
(iv) 5x ≡ 4(mod 6)

53
Modular Arithmetic
• Find the least positive value of x such that.
(i) 71 ≡ x (mod 8) Ans: 7
(ii) 78 + x ≡ 3 (mod 5)
(iii) 89 ≡ (x + 3) (mod 4)
(iv) 5x ≡ 4(mod 6)

54
Modular Arithmetic
• Find the least positive value of x such that.
(i) 71 ≡ x (mod 8) Ans: 7
(ii) 78 + x ≡ 3 (mod 5) Ans: 5
(iii) 89 ≡ (x + 3) (mod 4)
(iv) 5x ≡ 4(mod 6)

55
56
Modular Arithmetic
• Find the least positive value of x such that.
(i) 71 ≡ x (mod 8) Ans: 7
(ii) 78 + x ≡ 3 (mod 5) Ans: 5
(iii) 89 ≡ (x + 3) (mod 4)
(iv) 5x ≡ 4(mod 6)

57
Modular Arithmetic
• Find the least positive value of x such that.
(i) 71 ≡ x (mod 8) Ans: 7
(ii) 78 + x ≡ 3 (mod 5) Ans: 5
(iii) 89 ≡ (x + 3) (mod 4) Ans: 2
(iv) 5x ≡ 4(mod 6)

58
Modular Arithmetic
• Find the least positive value of x such that.
(i) 71 ≡ x (mod 8) Ans: 7
(ii) 78 + x ≡ 3 (mod 5) Ans: 5
(iii) 89 ≡ (x + 3) (mod 4) Ans: 2
(iv) 5x ≡ 4(mod 6) Ans: 2

59
Modular Arithmetic
• What is the remainder when 9813 + 7762 +
11252 is divided by 10?

60
Modular Arithmetic
• What is the remainder when 9813 + 7762 +
11252 is divided by 10?

ANS : 7

61
Modular Arithmetic

Modular Exponentiation

ap mod n

62
117 mod 13 = ?

63
117 mod 13 = ?

117 = 112 * 114 *11

117mod 13= 112 mod 13 * 114 mod 13 *11 mod 13

64
Modular Arithmetic
Modular Exponentiation

117 mod 13 = ?
117 = 112 * 114 *11 117 = 112 * 114 *11
112 = 121 mod 13
= 9*13 +4 mod 13
= 4 mod 13
=4

65
Modular Arithmetic
Modular Exponentiation

114 = (112)2mod 13
= 42 mod 13
117 mod 13 = ?
= 16 mod 13
117 = 112 * 114 *11
=3
112 = 121 mod 13
= 9*13 +4 mod 13
= 4 mod 13 117 = 112 * 114 *11
=4

66
Modular Arithmetic
Modular Exponentiation

114 = (112)2mod 13
= 42 mod 13
117 mod 13 = ?
= 16 mod 13
117 = 112 * 114 *11
=3
112 = 121 mod 13
= 9*13 +4 mod 13 117 = 112 * 114 *11
= 4 mod 13 Now apply all
=4 117 = 112 * 114 *11 mod 13
=4 * 3 *11 mod 13
= 132 mod 13
= 130 mod 13 +2 mod 13
= 0 + 2 mod 13
= 2 mod 13
=2
67
Modular Arithmetic
Modular Exponentiation
117 mod 13 = ?
117 = 112 * 114 *11
112 = 121 mod 13
= 9*13 +4 mod 13
= 4 mod 13
=4
114 = (112)2mod 13
= 42 mod 13
= 16 mod 13
=3
Now apply all
117 = 112 * 114 *11 mod 13
=4 * 3 *11 mod 13
= 132 mod 13
= 130+2 mod 13
= 2 mod 13
=2
68
Fast Modular Exponentiation
ab mod c = ?

Ex: 329 mod 7 = ?


24 23 22 21 20
16 8 4 2 1
1 1 1 0 1  16+8+4+1 = 29
29 = (20 +22+23+24 )

329 mod 7 = 316+8+4+1mod 7


= 316 mod 7 * 38 mod 7 * 34 mod 7 * 31 mod 7

69
329 mod 7 = 316+8+4+1mod 7
= 316 mod 7 * 38 mod 7 * 34 mod 7 * 31 mod 7
316 mod 7 = 316 mod 7
31 mod 7 = 3
= (38)2 mod 7
34 mod 7 = 32 mod 7 * 32 mod 7
= 22 mod 7
= 9 mod 7 * 9 mod 7
= 4 mod 7
= 2 * 2 mod 7
=4
= 4 mod 7
329 mod 7 = 316 mod 7 * 38 mod 7 * 34 mod 7 *
=4 31 mod 7
38 mod 7 = 34+4 mod 7 = 4 * 2 *4 * 3 mod 7
= 34 mod 7 * 34 mod 7 = 96 mod 7
= 4 * 4 mod 7 = 5 mod 7
= 16 mod 7 =5
=2
329 mod 7 = 5
70
Modular Arithmetic
• Rules for ordinary arithmetic involving addition, subtraction, and
multiplication carry over into modular arithmetic

71
Modular Arithmetic

72
Modular Arithmetic

73
Modular Arithmetic
Additive inverse:
• Negative of an integer x is the integer y such that (x + y) mod 8 = 0.
• To find the additive inverse of an integer in the left-hand column, scan across
the corresponding row of the matrix to find the value 0; the integer at the top
of that column is the additive inverse; thus, (2 + 6) mod 8 = 0.

Multiplicative inverse:
• Entries in the multiplication table are straightforward.
• In modular arithmetic mod 8, the multiplicative inverse of x is the integer y
such that (x * y) mod 8 = 1 mod 8.
• Now, to find the multiplicative inverse of an integer from the multiplication
table, scan across the matrix in the row for that integer to find the value 1; the
integer at the top of that column is the multiplicative inverse; thus, (3 * 3) mod
8 = 1.
• Note that not all integers mod 8 have a multiplicative inverse;
74
Additive inverse Multiplicative inverse

(x + y) mod 8 = 0 (x * y) mod 8 = 1 mod 8

75
Additive inverse Multiplicative inverse

76
Modular Arithmetic
0 1

77
Modulo 8 Multiplication

• In modular arithmetic mod 8, the multiplicative


inverse of x is the integer y such that
(x x y) mod 8 = 1 mod 8

• Now, to find the multiplicative inverse of an


integer from the multiplication table

• scan across the matrix in the row for that integer to


find the value 1

78
Modulo 8 Multiplication

• In general, an integer has a multiplicative inverse


in Zn if that integer is relatively prime to n

• Integers 1, 3, 5, and 7 have a multiplicative inverse


in Z 8

• but 2, 4, and 6 do not

79
Modular Arithmetic
Relative prime:
• Two integers are relatively prime if their only common
positive integer factor is 1.
GCD(n1,n2)=1 , where n1 & n2 are integers
• Ex: 4 and 21
• Factors of 4 : {1, 2, 4}
• Factors of 21 : {1, 3, 7, 21}

GCD(4,21) = 1
• So these are relative prime

80
Modular Arithmetic

Not a relative prime:


GCD(n1,n2)≠1 , where n1 & n2 are integers

EX: 6 and 8
Factors of 6 : {1, 2, 3, 6}
Factors of 8 : {1, 2, 4, 8}

GCD(6,8)=2
So these are not relative prime

81
Modular Arithmetic

If (a x b) = (a x c) (mod n) then b = c (mod n) if a is relatively


prime to n

• Integer has a multiplicative inverse in Zn if and only if that


integer is relatively prime to n.

82
Modular Arithmetic Properties

83

You might also like