|
|
|
[求助]关于求Fp上模逆的疑问??
上面给出的模逆运算错误, 无符号运算--有的结果对有的结果不对 =============== #include <stdlib.h> #include <iostream> using namespace std; // 无符号运算模逆 unsigned long ModInv(unsigned long A, unsigned long P) { unsigned long u = A, v = P; unsigned long x1 = 1, x2 = 0, flag=0; unsigned long q, r, x; while (u != 1) { q = v/u; r = v%u; x = q*x1 + x2; v = u; u = r; x2 = x1; x1 = x; flag = flag^1; } if (flag == 1) x1 += P; return x1%P; }; // 有符号运算模逆 long long ModInv(long long A, long long P) { long long u = A, v = P; long long x1 = 1, x2 = 0; long long q, r, x; while (u != 1) { q = v/u; r = v%u; x = x2 - (q*x1); v = u; u = r; x2 = x1; x1 = x; } x1 %= P; if (x1 < 0) x1 += P; return x1; }; int main() { cout << "Hello, world" << endl; //////////////////// // 65521是素数 unsigned long x, a, p = 65521; long long X, A, P; //65521是2字节, a一定也小于2字节, a*a一定小于4字节, 不会溢出. for (unsigned i=0; i<20; i++) { a = rand(); a %= p; A = a; P = p; cout << "计算: a=" << a << " p=" << p << endl; X = ModInv(A, P); A *= X; A %= P; if (A == 1) cout << "有符号模逆运算成功: " << X << endl; else cout << "有符号模逆运算失败: " << X << " **" << endl; x = ModInv(a, p); a *= x; a %= p; if (a == 1) cout << "无符号模逆运算成功: " << x << endl; else cout << "无符号模逆运算失败: " << x << " **" << endl; cout << endl; } return 0; }; // x = x2 - (q*x1); 最麻烦的这步 // 如果x1和x2的符号不相等, 可以直接相加. // 如果x1和x2的符号相等(同为负数或正数), 还要比较大小, 然后大的减小的, 差为正数. // 希望有更简单的办法 |
|
|
|
[原创]Montgomery乘法介绍
楼主, 我想写个 Montgomery乘法 的演示代码, 你能给看看对不对嘛? 我没数学基础。 |
|
[求助]哪能找到基于ECC算法的证书, 我想看看ECC的参数在证书里是怎么存放的?
我只想要个 ECC证书 , 可需要给他一个域名email, 我哪有域名。 |
|
[求助] 约减 是什么意思? 我实在搜不到只好来这问?
多项式规约 ??? |
|
[求助]“二进制域运算”的资料, 网上哪能找到?
冯克勤写的吗? 没找到书中有 二进制有限域 的内容 |
|
[求助]我们论坛上的大数运算库bigint, RSA运算值和openssl不一致!
谢谢! 真没想到还有 “数据补齐方式” 一说。 搜了一下: Usage: rsautl [options] -in file input file (输入准备要进行加密或解密的文件) -out file output file (输出加密或解密后的文件) -inkey file input key (输入密钥文件) -keyform arg private key format - default PEM (指定密钥文件格式) -pubin input is an RSA public (说明输入的是公钥) -certin input is a certificate carrying an RSA public key (指明输入的是一个证书) -ssl use SSL v2 padding (数据补齐方式,默认是pkcs) -raw use no padding (数据补齐方式,默认是pkcs) -pkcs use PKCS#1 v1.5 padding (default) (数据补齐方式,默认是pkcs) -oaep use PKCS#1 OAEP (数据补齐方式,默认是pkcs) -sign sign with private key (进行数字签名,即使有私钥加密) -verify verify with public key (进行数字签名验证,即使有公钥解密) -encrypt encrypt with public key (进行解密操作) -decrypt decrypt with private key (进行解密操作) -hexdump hex dump output (输出十六进制格式) -engine e use engine e, possibly a hardware device. -passin arg pass phrase source (口令参数) |
|
|
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值