コード例 #1
0
        public void decrypt(ref byte[] cipher)
        {
            #region Origin aglorigth
            //BigInteger c = new BigInteger(crypt);
            //BigInteger e = MathUlti.fastExponent(c, SECRET_KEY, N);
            //System.Array.Clear(crypt, 0, crypt.Length);
            //e.ToByteArray().CopyTo(crypt, 0);
            //return crypt;
            #endregion

            //System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();

            //Chinese Remainder Theorem
            BigInteger c = new BigInteger(cipher);
            //Debug.showLog("1", sw.ElapsedMilliseconds);
            m1 = MathUlti.fastExponent(c, dP, p);
            //Debug.showLog("2", sw.ElapsedMilliseconds);
            m2 = MathUlti.fastExponent(c, dQ, q);
            //Debug.showLog("3", sw.ElapsedMilliseconds);
            h = (m1 > m2) ? (qInv * (m1 - m2)) % p : ((qInv * (m1 - m2 + p)) % p);
            m = m2 + (h * q);
            //Debug.showLog("4", sw.ElapsedMilliseconds);
            System.Array.Clear(cipher, 0, cipher.Length);
            //Debug.showLog("5", sw.ElapsedMilliseconds);
            m.ToByteArray().CopyTo(cipher, 0);
            //Debug.showLog("6", sw.ElapsedMilliseconds);
            //sw.Stop();
        }
コード例 #2
0
        public void encrypt(ref byte[] plain)
        {
            BigInteger e = new BigInteger(plain);
            BigInteger c = MathUlti.fastExponent(e, PUBLIC_KEY, N);

            System.Array.Clear(plain, 0, plain.Length);
            c.ToByteArray().CopyTo(plain, 0);
        }
コード例 #3
0
 public void testFastExponent()
 {
     for (int i = 0; i < input.Length / 3; i += 3)
     {
         a = MathUlti.fastExponent(input[i], input[i + 1], input[i + 2]);
         b = BigInteger.ModPow(input[i], input[i + 1], input[i + 2]);
         Assert.AreEqual(a, b, "fastExponent wrong");
     }
 }