关于Tonelli-shanks陷入死循环这回事
NTL::ZZ ECC::Quadcongruence(NTL::ZZ A, NTL::ZZ P,int mes)
{
point Pm;
NTL::ZZ q = p - 1;
NTL::ZZ s = ZZ(0);
while (q % 2 == 0)
{
q =NTL::operator/=(q,2);
s =NTL::operator+=(s,1);
}
if (s == ZZ(1)) // p同余3mod4
{
Pm.y = NTL::PowerMod(A, (p + 1) / 4, p);//明文嵌入后的坐表
return Pm.y;
}
NTL::ZZ flag;
for (NTL::ZZ i = ZZ(2); i < p; i++)
{
if (p - 1 == Quadresidue(i))
{
flag = i; //找到最小的i 让L(i,p)=-1
break;
}
}
NTL::ZZ c = NTL::PowerMod(flag, q, p);
NTL::ZZ r = NTL::PowerMod(A, (q + 1) / 2, p);
NTL::ZZ t = NTL::PowerMod(A, q, p);
NTL::ZZ m = s;
NTL::ZZ t2 = NTL::ZZ(0);
while (NTL::SubMod(t,1,p)!= 0)
{
t2 = NTL::MulMod(t,t,p);
NTL::ZZ flag2;
for (NTL::ZZ i = ZZ(1); i < m; i++)
{
if (NTL::SubMod(t2,1,p) == 0)
{
flag2 = i;
cout << "flag2:" << flag2 << endl;
break;
}
t2 = NTL::MulMod(t2,t2,p);
}
NTL::ZZ b = NTL::PowerMod(c, NTL::operator<<(m - flag2 - ZZ(1), 1), p); //要左移重载
r = NTL::MulMod(r, b, p);
c = NTL::MulMod(b, b, p);
t = NTL::MulMod(t, c, p);
cout << "t: " << t << endl;
m = flag2;
//cout << "m的值" << m << endl; //在这个地方卡死了 要注意上方A值的变化
}
Pm.y = r; //明文嵌入后y的坐标 较小偏移量的y点
cout << "嵌入明文的y坐标是:" << Pm.y<<endl;
return Pm.y;
}
###### 为什么通过不了内层循环!while(NTL::SubMod(t,1,p)!= 0) ==while((t-1)%p!=0) (我调用了NTL库中的大数函数)