⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 新建 文本文档.txt

📁 RSA一个简单的C语言算法实现
💻 TXT
字号:
RSA算法c语言实现
这个是我帮个朋友写的,写的时候发现其实这个没那么复杂,不过,时间复杂度要高于那些成型了的,为人所熟知的RSA算法的其他语言实现.
 
 
#include <stdio.h>
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",r);
return r;
}
void main()
{
 int p,q,e,d,m,n,t,c,r;
 char s;
{printf("input the p:\n");
 scanf("%d\n",&p);
 printf("input the q:\n");
 scanf("%d%d\n",&p); 
 n=p*q;
 printf("so,the n is %3d\n",n);
 t=(p-1)*(q-1);
 printf("so,the t is %3d\n",t);
 printf("please intput the e:\n");
 scanf("%d",&e);
 if(e<1||e>t)
 {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 %5d",d);
  printf("if you want to konw the cipher please input 1;\n if you want to konw the plain  please input 2;\n");
  scanf("%d",&r);
  if(r==1)
{
 printf("input the m :" );/*输入要加密的明文数字*/
 scanf("%d\n",&m);
  c=candp(m,e,n);
 printf("so ,the cipher is %4d",c);}

if(r==2)
{
printf("input the c :" );/*输入要解密的密文数字*/
 scanf("%d\n",&c);
  m=candp(c,d,n);
 printf("so ,the cipher is %4d\n",m); 
 printf("do you want to use this programe:Yes or No");
 scanf("%s",&s);
}while(s=='Y');
 

}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -