示例#1
0
 public static BigInteger CreateRandomInRange(BigInteger min, BigInteger max, SecureRandom random)
 {
     int num = min.CompareTo(max);
     if (num >= 0)
     {
         if (num > 0)
         {
             throw new ArgumentException("'min' may not be greater than 'max'");
         }
         return min;
     }
     if (min.BitLength > (max.BitLength / 2))
     {
         return CreateRandomInRange(BigInteger.Zero, max.Subtract(min), random).Add(min);
     }
     for (int i = 0; i < 0x3e8; i++)
     {
         BigInteger integer = new BigInteger(max.BitLength, random);
         if ((integer.CompareTo(min) >= 0) && (integer.CompareTo(max) <= 0))
         {
             return integer;
         }
     }
     return new BigInteger(max.Subtract(min).BitLength - 1, random).Add(min);
 }
示例#2
0
 public static BigInteger GeneratePrivateValue(IDigest digest, BigInteger N, BigInteger g, SecureRandom random)
 {
     int num = Math.Min(0x100, N.BitLength / 2);
     BigInteger min = BigInteger.One.ShiftLeft(num - 1);
     BigInteger max = N.Subtract(BigInteger.One);
     return BigIntegers.CreateRandomInRange(min, max, random);
 }
示例#3
0
 public BigInteger Add(BigInteger value)
 {
     if (this.sign == 0)
     {
         return value;
     }
     if (this.sign == value.sign)
     {
         return this.AddToMagnitude(value.magnitude);
     }
     if (value.sign == 0)
     {
         return this;
     }
     if (value.sign < 0)
     {
         return this.Subtract(value.Negate());
     }
     return value.Subtract(this.Negate());
 }