RSA 算法的实现一、实验目的1
熟悉公钥密码体制;2
掌握产生密钥对的程序设计方法;3
掌握产生加密 / 解密的程序设计方法
二、实验内容和要求1
进行 RSA加密 / 解密算法的设计;2
对 RSA程序进行编译和调试;3
使用编写的程序进行加密和解密
三、实验环境运行 Windows操作系统的 PC机,可以利用具有VC++语言环境;如果所运用的语言是 JAVA,那么也可以利用JAVA语言环境来实现RSA算法的加密和解密
四、实验步骤1
采用 C++语言进行本次实验的编写,实验的代码如下:#include #include int candp(int a,int b,int c) { int r=1; b=b+1; while(b
=1) { r=r*a; r=r%c; b--; } printf("%d\n",r); return r; } void main() { int p,q,e,d,m,n,t,c,r; char s; printf("please input the p,q: "); scanf("%d%d",&p,&q); n=p*q; printf("the n is %3d\n",n); t=(p-1)*(q-1); printf("the t is %3d\n",t); printf("please input the e: "); scanf("%d",&e); if(et) { printf("e is error,please input again: "); scanf("%d",&e); } d=1; while(((e*d)%t)
=1) d++; printf("then caculate out that the d is %d\n",d); printf("the cipher please input 1\n");