1. 程式人生 > >密碼學 數論入門 Fermat Theorem 實戰

密碼學 數論入門 Fermat Theorem 實戰

  • 對兩個連續整數n和n+1,為什麼gcd(n,n+1)=1?

Because when n+1 is divided by n then remainder is 1. Therefore 1 is  the GCD of n, n+1

 

  • 利用費馬定理計算3^201 mod 11

Fermat theorem explains a^p-1 =1 mod p, where p is a prime number and a is positive number that is not disvisible by p.

3^201 mod 11= (3^1 mod 11)* (3^200 mod 11) mod 11 =(3^1 mod 11) * (3^10 mod 11)^20 mod 11

By using Fermat's rule a^p-1 =1 mod p

= (3^1 mod 11) *(1 mod 11)^20 mod 11

=1* 3 mod 11

=3

  • 利用費馬定理找一個0~72之間的數a,使得a模73與9^794同餘

Fermat's theorem explain a^p-1 = 1 mod p

9^794 mod 73

=(9^720 mod 73) * (9^74 mod 73)  mod 73

=(9^72 mod 73)^10 * (9^74 mod 73) mod 73

By fermat's rule 9^72 mod 73=1 mod 73

=1* (9^74 mod 73) mod 73

=(9^72)mod 73 * 9^2 mod 73

=81mod 73

=8

  • 利用費馬定理找一個位於0~28之間的數 x,使得 x^85 模29與6 同餘

Fermat's theorem explains the following,

a^p-1 =1 mod p ,  p is a prime, a is a positive integer 

Another alternative form of Fermat's theorem is used in the problem.

a^p = a mod p, p is a prime, a is a positive