I am working on a small project with C language , it's an RSA text encrypting .
The code works but the problem is that it doesn't work if i choose a large key . I think that the problem is due to the modular arithmetic but i can't find the solution.
There is the code of the 2 functions :
ENCRYPT
unsigned int crypt( unsigned int mchiff, unsigned int n,unsigned int e)
{
unsigned int i;
double cc=1;
printf("\n\n\n");
for(i=0;i<e;i++)
{
cc=cc*mchiff;
printf(" : %g : ",cc);
cc=fmod(cc,n);
printf(" < %g > \n",cc);
}
printf("\n\n\n");
return cc;
}
DECRYPT
unsigned long int decrypt(long cc,int n,int d)
{
int i;
unsigned long int cd=1;
for(i=0;i<d;i++) /* the main problem is here if the d is apprx equal to 2^1024 */
{
cd=cd*cc;
cd=cd%n;
}
return cd;
}