genCoPrime() public method

public genCoPrime ( int bits, Random rand ) : BigInteger
bits int
rand Random
return BigInteger
Exemplo n.º 1
0
        public void TestGenCoPrime()
        {
            { // Test small values
                var bi  = new BigInteger();
                var rng = new RNGCryptoServiceProvider();

                bi.genRandomBits(100, rng);

                var coprime = bi.genCoPrime(10, rng);

                Assert.IsTrue((bi.gcd(coprime)).getBytes()[0] == 1);
            }

            { // Test arbitrary values
                var bi   = new BigInteger();
                var rng  = new RNGCryptoServiceProvider();
                var rand = new Random();

                bi.genRandomBits(rand.Next(2241), rng);

                var coprime = bi.genCoPrime(rand.Next(2241), rng);

                Assert.IsTrue((bi.gcd(coprime)).getBytes()[0] == 1);
            }
        }
Exemplo n.º 2
0
        public void TestGenCoPrime()
        {
            { // Test small values
                var bi  = new BigInteger();
                var rng = new RNGCryptoServiceProvider();

                bi.genRandomBits(100, rng);

                var coprime = bi.genCoPrime(10, rng);

                Assert.Equal(1, (bi.gcd(coprime)).getBytes()[0]);
            }

            // Test arbitrary values
            for (int i = 0; i < 99; i++)
            {
                var bi   = new BigInteger();
                var rng  = new RNGCryptoServiceProvider();
                var rand = new Random();

                bi.genRandomBits(rand.Next(1, 32 * 69 + 1), rng);

                var coprime = bi.genCoPrime(rand.Next(1, 2241), rng);

                Assert.Equal(1, (bi.gcd(coprime)).getBytes()[0]);
            }
        }
Exemplo n.º 3
0
    public void init(int keysize = 512)
    {
        Random rand = new Random();

        m_e = m_pq.genCoPrime(keysize, rand);
        m_d = m_e.modInverse(m_pq);
    }
Exemplo n.º 4
0
    ///Encrypts plaintext m. Ciphertext em = g^m * r^n mod n^2.
    ///<param name="m">plaintext</param>
    ///<returns>ciphertext em</returns>
    public BigInteger Encryption(BigInteger m)
    {
        //generates random input r
        BigInteger r  = m.genCoPrime(bitLength, new Random());
        BigInteger em = ((g.modPow(m, nsqr)) * (r.modPow(n, nsqr))) % nsqr;

        return(em);
    }