當前位置:編程學習大全網 - 源碼下載 - rsa算法c語言實現

rsa算法c語言實現

程序修改如下: (主要是妳的循環寫的不對,輸入的字符應該-'0'才能與正常的數字對應)

#include<stdio.h>

#include<math.h>

int candp(int a,int b,int c)

{int r=1;

int s;

int i=1;

for(i=1;i<=b;i++)r=r*a;

printf("%d\n",r);

s=r%c;

printf("%d\n",s);

return s;}

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;

t=(p-1)*(q-1);

printf("the n is %12d\n",n);

printf("please input the e:");

scanf("%d",&e);

while(e<1||e>n) //此處修改為while循環

{

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");

printf("the plain please input 2\n");

scanf("%c",&s);

while((s-'0')!=1&&(s-'0')!=2) //消除後面的getchar() 此處增加while循環註意括號內的字符

{scanf("%c",&s);}

switch(s-'0')

{

case 1:printf("intput the m:");

scanf("%d",&m);

c=candp(m,e,n);

printf("the plain is %d\n",c);break;

case 2:printf("input the c:");

scanf("%d",&c);

m=candp(c,d,n);

printf("the cipher is %8d\n",m); break;

}

}

  • 上一篇:Html文件,實現上面導航和左邊欄不變,而右邊欄信息變化?是框架嗎?
  • 下一篇:查淘寶返利的軟件,查返利用什麽軟件
  • copyright 2024編程學習大全網