I want to encrypt (RSA) a character to an integer using its ASCII value. Eg. 'a' is encrypted as 48.
For encryption: c=pow(m,e)%n
where c is cipher text, m is the plain text and (e,n) is the public key.
If pow(m,e) is large say 67^7, it won't fit in int or long. But if I use double, I cannot use it with modulus % operator. So I wrote this function for encryption using a for loop:
int encrypt(int m, int e, int n)
{
int res=m, i;
for(i=0; i<e-1;i++)
res=(res*res)%n;
return res;
}
It worked for 67^7mod11 which is 67 but then I came to know it's not actually correct. Where have I gone wrong?