コード例 #1
0
ファイル: DSA.cs プロジェクト: lordalek/Assignment_3-DSA
        //#TODO
        //        Choose q first, where q is a random integer in the range 2^159 to 2^160; if q is not prime, try again. Choose k as a random even integer in the range 2^1023/q to 2^1024/q. Multiply q by k and add 1 to compute p, then test if p is prime; if not, try a different k

        //private static BigInteger GetPrimeDivisor(BigInteger p)
        //{
        //    var q =
        //    while ((p - 1) % q != 0)
        //    {
        //        q = PseudoRandomPrimeNumber.GetRandomPrimeNumber(160);
        //    }
        //    return q;
        //}

        public static void GetP(BigInteger q, BigInteger k, out BigInteger newK, out BigInteger p)
        {
            //var k = PseudoRandomPrimeNumber.GetRandomEvenNumber(q);
            p    = q * k;
            newK = k;
            while (!PseudoRandomPrimeNumber.IsPrime(p + 1))
            {
                k    = PseudoRandomPrimeNumber.GetRandomEvenNumber2(q);
                newK = k;
                p    = q * k;
            }
        }
コード例 #2
0
ファイル: DSA.cs プロジェクト: lordalek/Assignment_3-DSA
 public static void GetPublicKeyCompontents(out BigInteger p, out BigInteger q, out BigInteger k, out BigInteger g)
 {
     q = PseudoRandomPrimeNumber.GetRandomPrimeNumber2(160);
     GetP(q, PseudoRandomPrimeNumber.GetRandomEvenNumber2(q), out k, out p);
     g = (GetG(p, q));
 }