RSA加密源代码,平方乘算法,素数检测等算法

上传人:洪易 文档编号:39962418 上传时间:2018-05-21 格式:DOC 页数:5 大小:28.50KB
返回 下载 相关 举报
RSA加密源代码,平方乘算法,素数检测等算法_第1页
第1页 / 共5页
RSA加密源代码,平方乘算法,素数检测等算法_第2页
第2页 / 共5页
RSA加密源代码,平方乘算法,素数检测等算法_第3页
第3页 / 共5页
RSA加密源代码,平方乘算法,素数检测等算法_第4页
第4页 / 共5页
RSA加密源代码,平方乘算法,素数检测等算法_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《RSA加密源代码,平方乘算法,素数检测等算法》由会员分享,可在线阅读,更多相关《RSA加密源代码,平方乘算法,素数检测等算法(5页珍藏版)》请在金锄头文库上搜索。

1、RSA 加密源代码,平方乘算法,素数检测等算法.txt 和英俊的男人握握手,和深刻的男人谈谈 心,和成功的男人多交流,和普通的男人过日子。/RSA.cpp 函数功能实现#include “RSA.h“ #include #include #include /using namespace std;DataProcess:DataProcess() n=0; p=q=0; a=b=0; DataProcess:DataProcess() bool DataProcess:Miller_Rabin(long Mn) /prime 回答为 true,compose 回答为 false,Mn1long

2、 Mm=Mn-1; long Ma=0; long Mb=0; int k=0;/计数器while (!Mm +k; for (int j=0;j long Bq=0; long Bn=0; long s0=0,s=0; long t=0;/do / /srand(unsigned)time(NULL); /t=rand()%100; /Bp=4*t+3; / while (!Miller_Rabin(Bp);/p,q 均为素数,并且模 4 余 3/ /do / /srand(unsigned)time(NULL); /t=rand()%100;/产生两个小随机数 /Bq=4*t+3;/保证其

3、模 4 余 3/while (!Miller_Rabin(Bq);Bp=383; Bq=503; Bn=Bp*Bq;srand(unsigned)time(NULL); s=rand()%(Bn-1)+1;/s 取随机数,作为 s-1s0=(s*s)%Bn; for (int i=0;i c(power);/将幂次给转化为二进制 unsigned _int64 z=1;/z 初始化为 1,定义为 unsigned int64 防止在乘法时溢出for (int i=31;i=0;-i) z=(z*z)%mod; if (ci=1) z=(z*base)%mod; return (long)z;

4、long DataProcess:Euclidean_Extend(long Ea,long Eb)/b 在 a 群中的逆元 /返回它的逆元long a0=Ea; long b0=Eb; long t0=0; long t=1; long Eq=(long)(a0/b0); long r=a0-Eq*b0; long temp=0;while (r0) temp=(t0-Eq*t)%Ea; t0=t; t=temp; a0=b0; b0=r; Eq=(long)(a0/b0); r=a0-Eq*b0; if (b0!=1) return -1;/没有逆元else if (t B_b; bits

5、et B_p,B_q; B_p7=1; B_q6=1;/p,q 分别为 8 位,7 位,并且最高位置 1do Blum_Blum_Shub(B_p,6,7); while (!Miller_Rabin(long)B_p.to_ulong();do Blum_Blum_Shub(B_q,5,6); while (!Miller_Rabin(long)B_q.to_ulong();p=(long)B_p.to_ulong(); q=(long)B_q.to_ulong(); n=p*q; FN=(p-1)*(q-1);do B_b0=1;/最低位置 1Blum_Blum_Shub(B_b,10,11); b=B_b.to_ulong();/得到随机数 b,1bFNa=Euclidean_Extend(FN,b); while (a=-1);/a=-1 说明非互质,重算long DataProcess:Encrypt(long x) return Square_Multiply(x,b,n); long DataProcess:Decrypt(long y) return Square_Multiply(y,a,n);

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 研究报告 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号