I'm trying to implement RSA Encryption in C#. I have it working with small keys such as this:
public static int n = 33;
public static int e = 7;
public static int d = 3;
static void Main(string[] args)
{
int A = 9;
int enc = (int)(Math.Pow(A, e) % n);
int dec = (int)(Math.Pow(enc, d) % n);
Console.WriteLine(A);
Console.WriteLine(enc);
Console.WriteLine(dec);
}
This outputs:
9
15
9
I can't understand why it doesn't work with larger keys. If I give these key values:
public static int n = 3233;
public static int e = 17;
public static int d = 2753;
It outputs:
9
1971
-2147483648
According to Wikipedia (and checked with an RSA calculator from a university's website), n=3233 e=17 d=2753 is a valid RSA key set.
Can someone explain why I'm not getting the expected output?