Exemplo n.º 1
0
        // 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;
        }
Exemplo n.º 2
0
 public ULongIntB(ULongIntB From)
     : base((LongIntBinary)From)
 {
 }
Exemplo n.º 3
0
 public static ULongIntB Decode(RSAPrivateKey key, ULongIntB number)
 {
     return CryptoMath.ExpMod5(number, (ULongIntB)key.D, (ULongIntB)key.N);
 }
Exemplo n.º 4
0
        /// <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);
        }