1. 程式人生 > >公鑰密碼學 Miller-Rabin演算法(素性測試)

公鑰密碼學 Miller-Rabin演算法(素性測試)

Problem

Test all odd numbers in the range from 233 to 241 for primality using the Miller-Rabin test with base 2.

 

Answer:

test  n=233

  • 233-1=2^3 * 29, thus k=3, q=29
  • a^q mod n=2^29 mod 233=1
  • test returns"inconclusive"(probably prime)

 

test n=235

  • 235-1=2^1 * 117 ,thus k=1 q=117
  • a^q mod n=2^117 mod 235=222
  • 222!=1 and 222!=235-1
  • test returns "composite"

 

test n=237

  • 237-1=2^2 * 59, thus k=2, q=59
  • a^q mod n=2^59 mod 237=167!=1
  • 167!=237-1
  • 167^2 mod 237=160!=237-1
  • test returns "composite"

 

test n=239

  • 239-1=2^1 * 119
  • 2^119 mod 239=1
  • test returns "inconclusive"(probably prime)

 

test n=241

  • 241-1=2^4 *15
  • 2^15 mod 241=233
  • 233^2 mod 241=64
  • 64^2 mod 241=240=241-1
  • test returns "inconclusive"(probably prime)

 

問題思考

為什麼237測試兩遍就停了?為什麼不繼續往下平方測試

看K的值就知道了