0% found this document useful (0 votes)
3 views77 pages

Bcse309l Module1 Fermats Theorem

The document discusses Fermat's Theorem and its applications in modular arithmetic, including examples of calculating various moduli. It also covers concepts such as the multiplicative inverse and primality testing using Fermat's Theorem. The document provides numerous examples and exercises to illustrate these concepts.

Uploaded by

pspinjanispam
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)
3 views77 pages

Bcse309l Module1 Fermats Theorem

The document discusses Fermat's Theorem and its applications in modular arithmetic, including examples of calculating various moduli. It also covers concepts such as the multiplicative inverse and primality testing using Fermat's Theorem. The document provides numerous examples and exercises to illustrate these concepts.

Uploaded by

pspinjanispam
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
You are on page 1/ 77

BCSE309L – Cryptography and Network

Security
Fermat’s Theorem
To find modulus

2
Fermat’s Theorem

3
Fermat’s Theorem

4
Fermat’s Theorem

5
Fermat’s Theorem

6
Fermat’s Theorem
Example

7
Fermat’s Theorem

Example

8
Fermat’s Theorem
Example

Is gcd(5,19)=1?
Is 19 prime?
Is 5 positive integer?

Yes. So can apply fermat’s theorem to find mod


9
Fermat’s Theorem
Example

10
Fermat’s Theorem
Example

11
Fermat’s Theorem
Example

1 5

12
Fermat’s Theorem
Example

1 5

13
Fermat’s Theorem
Example

1 5 6

14
Fermat’s Theorem
Example

1 5 6

15
Fermat’s Theorem
Example

1 5 6

16
Fermat’s Theorem
Example

1 5 6

610 mod 11

17
Fermat’s Theorem
Example

1 5 6

610 mod 11

7 1

18
Fermat’s Theorem
Example

1 5 6

610 mod 11 312 mod 11

7 1

19
Fermat’s Theorem
Example

1 5 6

610 mod 11 312 mod 11

7 1 9

20
Fermat’s Theorem

719 mod 19 = ?

21
Fermat’s Theorem

719 mod 19 = 7

22
9794 mod 73 = ?

23
9794 mod 73 = ?

910*73+64 mod 73

24
9794 mod 73 = ?
794=10*73 + 64
So 9794 mod 73
= 910*73+64 mod 73
= (910)73+64 mod 73
= (910)73 mod 73 * 964 mod 73
= 910 mod 73 * 964 mod 73
= 910+64 mod 73
= 974 mod 73
= 973+1 mod 73
= 973 mod 73 * 91 mod 73
= 9 * 9 mod 73
= 81 mod 73
=8
9794 mod 73 = 8
25
Fermat’s Theorem

4532 mod 11

250 mod 17

26
Fermat’s Theorem

4532 mod 11  453*10+2 mod 11

250 mod 17

27
Fermat’s Theorem
4532 mod 11 = 453*10+2 mod 11
4532 mod 11 = (453)10 * 42 mod 11
= (453)10 mod 11 * 42 mod 11
= 1 * 42 mod 11
250 mod 17 = 42 mod 11
= 16 mod 11
=5
4532 mod 11 = 5

28
Fermat’s Theorem

4532 mod 11 5

250 mod 17 

29
Fermat’s Theorem

4532 mod 11 5

250 mod 17  23*16+2 mod 17

30
Fermat’s Theorem

250 mod 17 = 23*16+2 mod 17


4532 mod 11 5 = (23)16 *22 mod 17
= (23)16 mod 17 * 22 mod 17
= 1 * 22 mod 17
250 mod 17 = 22 mod 17
= 4 mod 17
=4
250 mod 17 = 4
31
Fermat’s Theorem
Answer

4532 mod 11 5

250 mod 17 4

32
4 225 mod 13 =?

33
4 225 mod 13 = ?

225=13*17+4

34
4 225 mod 13 = ?
4 225 mod 13 = 413*17+4 mod 13
= (417)13 * 44 mod 13
= (417)13 mod 13 * 44 mod 13
= 417 * 44 mod 13
= 421 mod 13
= 412 mod 13 * 49 mod 13
= 1 * 49 mod 13
= 49 mod 13
= 42 * 42 * 42 * 42 * 41 mod 13
= 42 mod 13 * 42 mod 13 * 42 mod 13 * 42 mod 13 * 41 mod 13
= 16 mod 13 * 16 mod 13 * 16 mod 13 * 16 mod 13 * 4 mod 13
= 3 * 3 * 3 * 3 * 4 mod 13
= 324 mod 13
= 12 mod 13
= 12
4 225 mod 13 = 12
35
4 225 mod 13 = 12

36
21000 mod 13 = ?

37
21000 mod 13 = 283*12+4 mod 13

38
21000 mod 13 = 283*12+4 mod 13
= 283*12 mod 13 * 24 mod 13
= (283)12 mod 13 * 24 mod 13
= 1 * 16 mod 13
= 3

21000 mod 13 = 3
39
128 129 mod 7 = ?

40
128129 mod 7 = ?

128129 mod 7 = 12821*6+3 mod 7

41
128129 mod 7 = ?
128129 mod 7 = 12821*6+3 mod 7
= 12821*6 mod 7 * 1283 mod 7
= (12821)6 mod 7 * 1283 mod 7
= 1 * 1283 mod 7
= 1281 mod 7 * 1281 mod 7 * 1281 mod 7
= (7*18+2) mod 7 * (7*18+2) mod 7 *(7*18+2) mod 7
= 2 * 2 * 2 mod 7
= 8 mod 7

=1

128129 mod 7 = 1

42
128 129 mod 17 = ?

43
128 129 mod 17 = ?

128129 mod 17 = 1288*16+1 mod 17

44
128129 mod 17 = 1288*16+1 mod 17
= 1288*16 mod 17 * 1281 mod 17
= (1288)16 mod 17 * 1281 mod 17
= 1 * 128 mod 17
= 128 mod 17
= (17*7+9) mod 17
=9

128129 mod 17 =9

45
Answer:

128129 mod 17 = 9

46
x 86 ≡ 6 mod 29
x=?

47
x 86 ≡ 6 mod 29
x=?
x2(29)+28 mod 29 = 6

48
We try all values from x = 1 to
x86 ≡ 6 mod 29 x = 28
(or)
x=?
x86 mod 29 = 6 6 mod 29
x86 mod 29 = x2(29)+28 mod 29 6+29 = 35 (not x2)
= (x2)29 mod 29 * x28 mod 29 35+29 =64 (x2)
= x2 mod 29 * x28 mod 29 = 82
= x2 mod 29 * 1
So x=±8
= x2 mod 29
x=8 mod 29
x86 mod 29 = x2 mod 29
x=-8 mod 29
(x86 mod 29 = 6)
So, x2 mod 29 = 6 Verify the answer
x2 = 6 mod 29 x86 ≡ 6 mod 29
886 mod 29 = 6
6 mod 29 = 6
6=6
49
Answer:
x86 ≡ 6 mod 29
x=±8

50
2 35 mod 7 = ?

51
2 35 mod 7 = 4

52
x 103 ≡ 4 mod 11
x=?
x10(10)+3 mod 11 = 4

53
x103 ≡ 4 mod 11
x103 mod 11 ≡ 4 mod 11 x103 ≡ 4 mod 11
x103 mod 11 = 4
x=?
x103 mod 11 = x10*10+3 mod 11
=(x10)10 mod 11 * x3 mod 11
= 1 * x3 mod 11
= x3 mod 11
x103 mod 11 = x3 mod 11
(x103 mod 11 = 4 )
x3 mod 11 = 4
53 mod 11 = 4
52 mod 11 * 5 mod 11 = 4
25 mod 11 * 5 mod 11 =4
3*5 mod 11 =4
15 mod 11 = 4 So, x=5
4=4 54
Answer:
x103 ≡ 4 mod 11
x=5

55
For Practice

• 2925 mod 11 = ?

• 331 mod 7 = ?

56
For Practice

• 2925 mod 11 = 10

• 331 mod 7 = 3

57
Fermat’s Theorem

8 -1 mod 17 = ?

58
Multiplicative Inverse

59
Fermat’s Theorem

8 -1 mod 17 = ?

60
Fermat’s Theorem

61
Fermat’s Theorem

8 -1 mod 17 = ?

62
Fermat’s Theorem
8-1 mod 17 = ?

8-1 mod 17 = 817-2 mod 17


= 815 mod 17

63
8-1 mod 17 = ?
8-1 mod 17 = 817-2 mod 17
= 815 mod 17
= 82*82*82*82*82*82*82*81 mod 17
= 13 * 13 *13 *13 *13 *13 *13 *8 mod 17 82 mod 17 = 64 mod 17
= 169 * 169 * 169 * 104 mod 17 = 13

= 169 mod 17 * 169 mod 17 * 169 mod 17 * 104 mod 17


=16 * 16 * 16 * 2 mod 17
= 256 * 32 mod 17
= 1 * 15 mod 17
= 15 mod 17
= 15

8-1 mod 17 = 15
64
8-1 mod 17 = ?
Multiplicative Inverse using Extended Euclidean Algorithm
8-1 mod 17 = ?

t1 t2 t

65
8-1 mod 17 = ?
Multiplicative Inverse using Extended Euclidean Algorithm
8-1 mod 17 = ?

t1 t2 t

66
8-1 mod 17 = ?
Multiplicative Inverse using Extended Euclidean Algorithm
8-1 mod 17 = ?

t1 t2 t

8-1 mod 17 = -2 mod 17


= 17+(-2) mod 17 (to represent as positive number add 17 and (-2)
= 15 mod 17

8-1 mod 17 = 15 67
14 -1 mod 11 = ?

68
14-1 mod 11 = ?

t1 t2 t=t1-qt2

69
11-1 mod 26 = ?

70
11-1 mod 26 = 19

71
Fermat’s Theorem

72
Primality Testing

73
Primality Testing
Find p is prime or not?
p =7, a = 3
ap-1 ≡ 1 (mod p)

74
Primality Testing
Find p is prime or not?
p =7, a = 3
ap-1 ≡ 1 (mod p)
Substitute the given numbers in the above equation
37-1 ≡ 1 (mod 7)
37-1 mod 7 ≡ 1 mod 7
36 mod 7 ≡ 1 mod 7
32 32 32 mod 7 ≡ 1 mod 7
9*9*9 mod 7 ≡ 1 mod 7
2*2*2 mod 7 ≡ 1 mod 7
8 mod 7 ≡ 1 mod 7
8 mod 7 ≡ 1 mod 7 p is prime
1=1 7 is prime 75
Primality Testing
Find p is prime or not?
p = 6, a = 3
ap-1 ≡ 1 (mod p)

76
Primality Testing
Find p is prime or not?
p = 6, a = 3
ap-1 ≡ 1 (mod p)
Substitute the given numbers in the above equation
36-1 ≡ 1 (mod 6)
36-1 mod 6 ≡ 1 mod 6
35 mod 6 ≡ 1 mod 6
32 32.31 mod 6 ≡ 1 mod 6
9.9.3 mod 6 ≡ 1 mod 6
3.3.3 mod 6 ≡ 1 mod 6
9 mod 6 * 3 mod 6 ≡ 1 mod 6
3 * 3 mod 6 ≡ 1 mod 6 p is not prime
9 mod 6 ≡ 1 mod 6 6 is not prime
3 ≠ 1 77

You might also like