public static PublicKey Generate(int p, int q) { var n = p * q; var phi = (p - BigInt.BigInt.One) * (q - BigInt.BigInt.One); BigInt.BigInt e = 3; while (BigInt.BigInt.GreatestCommonDivisor(e, phi) != BigInt.BigInt.One) { e += BigInt.BigInt.One; } return(new PublicKey(e, n, phi)); }
public void BigIntSum() { int maxValue = 100; for (int i = 0; i < maxValue; i++) { for (int j = 0; j < maxValue; j++) { BigInt.BigInt first = new BigInt.BigInt(i.ToString()); BigInt.BigInt second = new BigInt.BigInt(j.ToString()); BigInt.BigInt resultSum = first + second; uint result = (uint) (i + j); Assert.AreEqual(result.ToString(), resultSum.Value); } } }
public async Task <BigInt.BigInt[]> Encrypt(string text, PublicKey publicKey, IProgress <double> progress = default) { var textBytes = StringUtils.ConvertToNumbers(text.ToLower(), _alphabet); var encrypted = new BigInt.BigInt[textBytes.Length]; await Task.Run(() => { for (var i = 0; i < textBytes.Length; i++) { encrypted[i] = RsaEncrypting.EncryptNumber(textBytes[i], publicKey); progress?.Report(100.0 / text.Length *i); } progress?.Report(100); }); return(encrypted); }
public void TestBigValue() { // ------------------------------------------ Stopwatch sw = Stopwatch.StartNew(); string firstString = "1234567891234567891234567893216549872222222222222222222222222222222222222222222222222222222233333333333333333333333333333" + "99999999999999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999999999999" + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"; string secondString = "555555555555555555555555555555555555555555555777777777777777777777772222222222222222222222222222222222222225465465465464654654646" + "555555555555555555555555555555555555555555555543242324444444444444444444444444444444444499999999999999999999999999999999999" + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999" + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999" + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999" + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999" + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999" + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999" + "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999" + ""; BigInteger bigIntegerFirst = BigInteger.Parse(firstString); BigInteger bigIntegerSecond = BigInteger.Parse(secondString); BigInteger expected = bigIntegerFirst + bigIntegerSecond; BigInt.BigInt firstBigINt = new BigInt.BigInt(firstString); BigInt.BigInt secondBigINt = new BigInt.BigInt(secondString); var result = firstBigINt + secondBigINt; sw.Stop(); Assert.AreEqual(expected.ToString(), result.Value); // Debug.WriteLine("{0} + {1}. Time taken: {2}ms", i, j, sw.Elapsed.TotalMilliseconds); }
public void BigIntConstructorSuccessTest() { string correctBigInt = "123456789111444444444444444444444444444444444"; BigInt.BigInt bigInt = new BigInt.BigInt(correctBigInt); }
public void BigIntConstructorFailTest() { string correctBigInt = "123456789fsf111'"; BigInt.BigInt bigInt = new BigInt.BigInt(correctBigInt); }
public static int DecryptNumber(BigInt.BigInt number, PrivateKey privateKey) => int.Parse((BigInt.BigInt.Pow(number, privateKey.D) % privateKey.N).ToString());
public PublicKey(BigInt.BigInt e, BigInt.BigInt n, BigInt.BigInt phi) { E = e; N = n; Phi = phi; }
public PrivateKey(BigInt.BigInt d, BigInt.BigInt n) { D = d; N = n; }