我能够解决这个问题。即使是大数字,加密也能正常工作。但是,解密单元存在一些问题。有人可以帮助我吗?
main()
{
//__uint128_t secret=((__uint128_t)3502532219136638976) <<64 |1161929539123609600;
//__uint128_t pvtkey=((__uint128_t)14605469131018042215) <<64 |1281687108645159073;
//__uint128_t n=((__uint128_t)16156614574048939703) <<64| 17372945349702060311;
decrypt(1434,1293,2491);
}
__uint128_t decrypt(__uint128_t secret,__uint128_t pvtkey,__uint128_t n)
{
cout<< "Decrypting..."<<"\n";
__uint128_t imsg_copy2=pvtkey;
uint64_t imsg64_lo2,imsg64_hi2;
imsg64_lo2=imsg_copy2;
imsg_copy2=imsg_copy2>>64;
imsg64_hi2=imsg_copy2;
cout << "Pvt key recvd here:"<<imsg64_lo2<<"\n";
cout << "Pvt key recvd here hi:"<<imsg64_hi2<<"\n";
__uint128_t r=1;
int ctr=0;
while(1)
{
if(((__uint128_t)pvtkey)%2==1)
{r=(((__uint128_t)r)*((__uint128_t)secret))%((__uint128_t)n);
cout<<" r:" << r << "\n" ;
}
// cout <<"Dividing";
pvtkey=((__uint128_t)pvtkey)/2;
cout << "r:";
printf_128(r);
cout << ctr << "\n";
if(pvtkey==0)
break;
cout<<"secret:";
secret=(((__uint128_t)secret)*((__uint128_t)secret)%((__uint128_t)n));
printf_128(secret);
ctr++;
cout << "Decryption inside function_lo:"<<"\n";
printf_128(r);
return ((__uint128_t)r);
}
void printf_128(__uint128_t v)
{
__uint128_t imsg_copy=v;
uint64_t imsg64_lo,imsg64_hi;
imsg64_lo=imsg_copy;
imsg_copy=imsg_copy>>64;
imsg64_hi=imsg_copy;
cout <<imsg64_hi<<imsg64_lo<<"\n";
}
因此,当我为较小的数字运行此函数时,解密单元工作正常。但是,当我为大型公钥执行此操作时,所有值都设置为0.可以有人帮忙吗?
答案 0 :(得分:0)
你将两个128位数相乘,这将在你的代码中给出一个128位的数字 - 但你需要完整的结果(一个256位的数字),然后计算结果模型。