public string Decrypt(BigInteger[,] encryptedText)
 {
     byte[] decryptedText = new byte[encryptedText.GetUpperBound(0) + 1];
     for (int i = 0; i < encryptedText.GetUpperBound(0) + 1; i++)
     {
         BigInteger inverseA = GCD.ModInverse(BigInteger.Pow(encryptedText[i, 0], (int)x), p);
         decryptedText[i] = Convert.ToByte(BigInteger.ModPow(BigInteger.Multiply(encryptedText[i, 1], inverseA), 1, p).ToString());
     }
     return(Encoding.ASCII.GetString(decryptedText));
 }
Example #2
0
 public RSA()
 {
     p  = GeneratePrimeNumber();
     q  = GeneratePrimeNumber();
     n  = p * q;
     fi = (p - 1) * (q - 1);
     e  = GenerateCoprimeNumber(fi);
     d  = GCD.ModInverse(e, fi);
     Console.WriteLine(new string('-', 40) + "RSA" + new string('-', 40));
     Console.WriteLine($"p = {p}, q = {q}, n = p * q = {p * q}, fi(n) = {fi}, e = {e}, d = {d}\n");
     Console.WriteLine($"PUBLIC KEY: (e, n) = ({e}, {n})");
     Console.WriteLine($"PRIVATE KEY: (d, n) = ({d}, {n})");
     Console.WriteLine();
 }