欢迎来到天天文库
浏览记录
ID:50943006
大小:22.00 KB
页数:2页
时间:2020-03-16
《密钥互换加密算法dh算法.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#includeunsignedlongpow(intx,inty){unsignedlongr=1;inti;for(i=1;i<=y;i++){r=r*x;}returnr;}voidmain(){intn,a,b,t;unsignedlongx,y,k,l;printf("请输入n的值:");scanf("%d",&n);srand(time(0));a=(rand()%(n-2))+2;printf("随机数a的值:%d
2、",a);b=(rand()%(n-2))+2;printf("随机数b的值:%d",b);t=(rand()%(n-2))+2;printf("随机数t的值:%d",t);x=pow(t,a)%n;//计算t的a次幂,modn的值,并把结果发送给Bprintf("经计算得到x值并发送给B:%d",x);y=pow(t,b)%n;//计算t的b次幂,modn的值,并把结果发送给Aprintf("经计算得到Y值并发送给A:%d",y);k=pow(y,a)%n;printf("A计算结果k:%d
3、",k);l=pow(x,b)%n;printf("B计算结果l:%d",l);printf("a=%d,b=%d,t=%d",a,b,t);printf("x=%ld,y=%ldk=%ld,l=%ld",x,y,k,l);printf("得出的结果如果k与l相等,密钥分配成功;如果不等,请重新输入计算");}
此文档下载收益归作者所有