C语言中大整数的Miller-Rabin算法
Miller-Rabin试验可用伪代码描述如下:C语言中大整数的Miller-Rabin算法,c,C,Miller-Rabin试验可用伪代码描述如下: Let int n be a possible prime . Let int t be a security parameter . Write n-1 = 2^{s} * r for odd r . For i = 1 to t do Generate a random a in [2; n-2]. Let b=a^{r} mod n . If b!=1 and b!=-1 do
Let int n be a possible prime . Let int t be a security parameter .
Write n-1 = 2^{s} * r for odd r .
For i = 1 to t do
Generate a random a in [2; n-2]. Let b=a^{r} mod n .
If b!=1 and b!=-1 do
j=1
While j<=s-1 and b!=-1 do
Let b=b^{2} mod n
If b=1 return "composite"
j=j+1
If b!=-1 return "composite"
Return "prime"
设int n为可能的素数。设int t为安全参数。
为奇数r写入n-1=2^{s}*r。
对于i=1,不需要
在[2;n-2]中生成随机a。设b=a^{r}mod n。
如果b=1和b=-我做
j=1
通常情况下,根据您的目的,组装将用于mod exp步骤,最佳优化可能是使用一个小的t
:。如果您试图检查随机生成的512位奇数t=2
就足够了。