RSA C Program doesnt work
Code:
#include <stdio.h>
long GetPrivateKey(long m,long e){
long k=1;
while(1){
k=k+1;
if (1==(k*e)%m) return k;
}
}
main(){
long p,q,e,t=2,n,m;
printf("Your public key should be in the form(n,e),enter n: ");
fflush(stdout);
scanf("%ld",&n);
printf("enter e: ");
fflush(stdout);
scanf("%ld",&e);
for(; n > 1 ;)
{
if (n%t==0) {
p=t;
n/=t;
}
else{
++t;
if (t*t>n){
q=n;
break;
}
}
}
m=(p-1)*(q-1);
printf("Our private key: (%ld,%ld)\n",p*q,GetPrivateKey(m,e));
printf("%ld\n",m);
}
the question asks to make a program which can compute the private key by giving public key.
but public key is large: n = 1805760301 e= 50512913
and i try it with my program, but the answer was wrong!