當前位置:編程學習大全網 - 編程軟體 - 求用C語言編寫程序RSA算法

求用C語言編寫程序RSA算法

這個是我幫個朋友寫的,寫的時候發現其實這個沒那麽復雜,不過,時間復雜度要高於那些成型了的,為人所熟知的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");<br/> scanf("%d\n",&p);<br/> printf("input the q:\n");<br/> scanf("%d%d\n",&p); <br/> n=p*q;<br/> printf("so,the n is %3d\n",n);<br/> t=(p-1)*(q-1);<br/> printf("so,the t is %3d\n",t);<br/> printf("please intput the e:\n");<br/> scanf("%d",&e);<br/> if(e<1||e>t)<br/> {printf("e is error,please input again;");<br/> 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');

}

}

  • 上一篇:鄭州錦繡中原小區周邊配套怎麽樣?
  • 下一篇:編寫程序,用牛頓切線法求方程f(x)= x^2-x-8=0(其中^表示 冪運算)在區間[3,4]上的近似實根r,叠代初
  • copyright 2024編程學習大全網