コード例 #1
0
ファイル: PrimeGenerator.cs プロジェクト: Ribtoks/LongInt
        // also checks if GCD(result - 1, f) == 1
        /// <summary>
        /// Gets next prime number that is greater 
        /// equal than Min, and less, than Max and
        /// GCD(number - 1, f) = 1
        /// </summary>
        /// <param name="Min">Lower bound of interval</param>
        /// <param name="Max">Upper bound of interval</param>
        /// <param name="f">Number f</param>
        /// <returns>Prime long number</returns>
        public ULongIntB Next(ULongIntB Min, ULongIntB Max, SLongIntB f)
        {
            if (Min > Max)
                throw new ArgumentException("Lower bound is less, that upper bound!");

            if (LongMath.IsEven(f))
                throw new ArgumentException("Argument 'f' cannot be even!");

            ULongIntB p = new ULongIntB(rand.Next(Min, Max), ConstructorMode.Assign);
            ULongIntB t = Max - Min;

            if (LongMath.IsEven(p))
                ++p;

            if (p > Max)
                p = Min + (p % (t + 1));

            while (CryptoMath.TestPrimeMillerRabin(p, RoundsNumber.Rounds25) == PrimeTestResult.Composite
                   || (CryptoMath.GCD((SLongIntB)p - 1, f) == 1))
            {
                ++p;
                ++p;

                while (p > Max)
                {
                    p = Min + (p % (t + 1));
                    if (LongMath.IsEven(p))
                        ++p;
                }
            }

            return p;
        }
コード例 #2
0
ファイル: ULongIntB.cs プロジェクト: Ribtoks/LongInt
 public ULongIntB(ULongIntB From)
     : base((LongIntBinary)From)
 {
 }
コード例 #3
0
ファイル: RSADecoder.cs プロジェクト: Ribtoks/LongInt
 public static ULongIntB Decode(RSAPrivateKey key, ULongIntB number)
 {
     return CryptoMath.ExpMod5(number, (ULongIntB)key.D, (ULongIntB)key.N);
 }
コード例 #4
0
ファイル: RSAKeyGenerator.cs プロジェクト: Ribtoks/LongInt
        /// <summary>
        /// Calculates long random prime numbers
        /// </summary>
        /// <param name="bitLength">Length of prime numbers</param>
        private void CalculatePQ(BitLength bitLength)
        {
            ULongIntB min = (ULongIntB)0;
            min.SetBit((uint)bitLength);

            ULongIntB max = (ULongIntB)0;
            max.SetBit((uint)bitLength + 1);

            p = prGen.Next(min, max);

            //min.ShR(1);
            //max.ShR(1);

            q = prGen.Next(min, max);
        }