1、Cony公钥密码算法实验北京信息科技大学信息管理学院(课程上机)实验报告实验课程名称: 密码学 专业: 信息安全 班级: 信安140 学号: 姓名: Cony 成绩: 实验名称公钥密码算法实验实验地点1-3-702实验时间2016.05.261. 实验目的:使学生通过对各种公钥密码算法主要参数和其部分模块功能的验证,理解对公钥密码算法中主要参数的基本要求,从而深入理解公钥密码算法的设计原理。2. 实验内容:1) 在信息安全实验系统中完成RSA算法和Elgamal算法的系列实验。2) 复习教材上的Miller-Rabin素性检验算法和扩展的欧几里德算法,并编写程序将其实现,并分析实验结果。1.
2、2. #include stdio.h #include math.h#include malloc.h int * decToBin(int n) int i=0; for (i=0;i8;i+) if(n&128)=0) n=n1; else break; i-; int *temp; temp=(int*)malloc(n-i+1)*sizeof(int); *temp=n-i+1; temp+; for (i;i8;i+) if(n&128)=0) n=n1; *temp=0; else n=n0;i-) x=d; d=(d*d)%n; if (d=1&x!=1&x!=(n-1) re
3、turn 0; if (*temp=1) d=(d*a)%n; temp+; if(d!=1) return 0; return 1;int main() if (witness(5,7)=1) printf(result is true); else printf(result is false); return 0;#include stdio.h#include math.h#include malloc.hint euclid(int f,int d) int temp; temp=f%d; while(temp!=0) f=d; d=temp; temp=f%d; return d;
4、int ExtendedEuclid( int f,int d ,int *result);int main() int x; ExtendedEuclid(550,1769,&x); printf(gcd(18,12)=%dn,euclid(18,12); printf(550关于1769的乘法逆元为:%d,x); return 0;int ExtendedEuclid( int f,int d ,int *result) int x1,x2,x3,y1,y2,y3,t1,t2,t3,q; x1 = y2 = 1; x2 = y1 = 0; x3 = ( f=d )?f:d; y3 = (
5、f=d )?d:f; while( 1 ) if ( y3 = 0 ) *result = x3; return 0; if ( y3 = 1 ) *result = y2; return 1; q = x3/y3; t1 = x1 - q*y1; t2 = x2 - q*y2; t3 = x3 - q*y3; x1 = y1; x2 = y2; x3 = y3; y1 = t1; y2 = t2; y3 = t3; 3. 实验要求:1)通过完成信息安全实验系统中的RSA算法实验和ElGamal算法实验来验证算法中主要参数的选择和产生。 2)用C语言编写程序实现RSA算法中使用的Miller-Rabin素性检验算法和扩展的欧几里德算法,整理程序代码文档,记录程序运行结果。4. 实验准备:5实验过程:;6.实验总结: 说明:1. 实验名称、实验目的、实验内容、实验要求由教师确定,实验前由教师事先填好,然后作为实验报告模版供学生使用;2. 实验准备由学生在实验或上机之前填写,教师应该在实验前检查;3. 实验过程由学生记录实验的过程,包括操作过程、遇到哪些问题以及如何解决等;4. 实验总结由学生在实验后填写,总结本次实验的收获、未解决的问题以及体会和建议等;5. 源程序、代码、具体语句等,若表格空间不足时可作为附录另外附页。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1