Saturday, 28 September 2013

pow function and long int causing problems

pow function and long int causing problems

I am trying to impliment RSA encryption scheme. It goes something like this:
encrypted data = ((message)^e) % n
I tried to implement this in c. Here is the code :
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
long int num = 3255859;
long int encrypt =(int)pow((double) num,3) % 33;
printf("%ld\n",encrypt);
return 0;
}
I compiled this using gcc -Werror -g -o encrypt encrypt.c -lm
This is the output I get = -2, which is obviously wrong. When i try this
code for smaller numbers, I get the right result. For eg:
when I set num = 2, I get the right result which is 8
I know I am either type casting wrong or I am running out of boundaries
somewhere. I do need to use this code to encrypt large numbers like the
one in the code above.
Could you please point out where I am going wrong.
Thanks

No comments:

Post a Comment