当前位置: 首页>>代码示例>>C#>>正文


C# BigInteger.Equals方法代码示例

本文整理汇总了C#中BigInteger.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.Equals方法的具体用法?C# BigInteger.Equals怎么用?C# BigInteger.Equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BigInteger的用法示例。


在下文中一共展示了BigInteger.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Calculate

        /// <summary>
        /// Runs the EEA on two BigIntegers
        /// </summary>
        /// <param name="A">Quotient A</param>
        /// <param name="B">Quotient B</param>
        /// <returns>Return a BigIntEuclidean object that contains the result in the variables X, Y, and GCD</returns>
        /// 
        /// <remarks>
        /// Implemented from pseudocode on <a href="http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm"/>Wikipedia
        /// </remarks>
        public static BigIntEuclidean Calculate(BigInteger A, BigInteger B)
        {
            BigInteger x = BigInteger.Zero;
            BigInteger lastX = BigInteger.One;
            BigInteger y = BigInteger.One;
            BigInteger lastY = BigInteger.Zero;

            while (!B.Equals(BigInteger.Zero))
            {
                BigInteger[] quotientAndRemainder = A.DivideAndRemainder(B);
                BigInteger quotient = quotientAndRemainder[0];
                BigInteger temp = A;

                A = B;
                B = quotientAndRemainder[1];

                temp = x;
                x = lastX.Subtract(quotient.Multiply(x));
                lastX = temp;

                temp = y;
                y = lastY.Subtract(quotient.Multiply(y));
                lastY = temp;
            }

            BigIntEuclidean result = new BigIntEuclidean();
            result.X = lastX;
            result.Y = lastY;
            result.GCD = A;

            return result;
        }
开发者ID:DeadlyEmbrace,项目名称:NTRU-NET,代码行数:42,代码来源:BigIntEuclidean.cs

示例2: AndNot

        /** @see BigInteger#andNot(BigInteger) */
        public static BigInteger AndNot(BigInteger val, BigInteger that)
        {
            if (that.Sign == 0) {
                return val;
            }
            if (val.Sign == 0) {
                return BigInteger.Zero;
            }
            if (val.Equals(BigInteger.MinusOne)) {
                return that.Not();
            }
            if (that.Equals(BigInteger.MinusOne)) {
                return BigInteger.Zero;
            }

            //if val == that, return 0

            if (val.Sign > 0) {
                if (that.Sign > 0) {
                    return AndNotPositive(val, that);
                } else {
                    return AndNotPositiveNegative(val, that);
                }
            } else {
                if (that.Sign > 0) {
                    return AndNotNegativePositive(val, that);
                } else {
                    return AndNotNegative(val, that);
                }
            }
        }
开发者ID:tupunco,项目名称:deveel-math,代码行数:32,代码来源:Logical.cs

示例3: And

        /** @see BigInteger#and(BigInteger) */
        public static BigInteger And(BigInteger val, BigInteger that)
        {
            if (that.Sign == 0 || val.Sign == 0) {
                return BigInteger.Zero;
            }
            if (that.Equals(BigInteger.MinusOne)) {
                return val;
            }
            if (val.Equals(BigInteger.MinusOne)) {
                return that;
            }

            if (val.Sign > 0) {
                if (that.Sign > 0) {
                    return AndPositive(val, that);
                } else {
                    return AndDiffSigns(val, that);
                }
            } else {
                if (that.Sign > 0) {
                    return AndDiffSigns(that, val);
                } else if (val.numberLength > that.numberLength) {
                    return AndNegative(val, that);
                } else {
                    return AndNegative(that, val);
                }
            }
        }
开发者ID:tupunco,项目名称:deveel-math,代码行数:29,代码来源:Logical.cs

示例4: ValidatePublicValue

		public static BigInteger ValidatePublicValue(BigInteger N, BigInteger val)
		{
		    val = val.Mod(N);

	        // Check that val % N != 0
	        if (val.Equals(BigInteger.Zero))
	            throw new CryptoException("Invalid public value: 0");

		    return val;
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:10,代码来源:SRP6Utilities.cs

示例5: Not

        /// <summary>
        /// Returns a new BigInteger whose value is ~Value.
        /// <para>The result of this operation is <c>-this-1</c>.</para>
        /// </summary>
        /// 
        /// <param name="Value">Value to be Not'ed</param>
        /// 
        /// <returns>Returns <c>~Value</c></returns>
        internal static BigInteger Not(BigInteger Value)
        {
            if (Value._sign == 0)
                return BigInteger.MinusOne;
            if (Value.Equals(BigInteger.MinusOne))
                return BigInteger.Zero;

            int[] resDigits = new int[Value._numberLength + 1];
            int i;

            if (Value._sign > 0)
            {
                // ~val = -val + 1
                if (Value._digits[Value._numberLength - 1] != -1)
                {
                    for (i = 0; Value._digits[i] == -1; i++)
                    {
                        ;
                    }
                }
                else
                {
                    for (i = 0; (i < Value._numberLength) && (Value._digits[i] == -1); i++)
                    {
                        ;
                    }
                    if (i == Value._numberLength)
                    {
                        resDigits[i] = 1;
                        return new BigInteger(-Value._sign, i + 1, resDigits);
                    }
                }
                // Here a carry 1 was generated
            }
            else
            {
                // ~val = -val - 1
                for (i = 0; Value._digits[i] == 0; i++)
                    resDigits[i] = -1;
            }

            // Now, the carry/borrow can be absorbed
            resDigits[i] = Value._digits[i] + Value._sign;
            // Copying the remaining unchanged digit
            for (i++; i < Value._numberLength; i++)
                resDigits[i] = Value._digits[i];

            return new BigInteger(-Value._sign, i, resDigits);
        }
开发者ID:DeadlyEmbrace,项目名称:NTRU-NET,代码行数:57,代码来源:Logical.cs

示例6: VerifyCtorInt32

        private static bool VerifyCtorInt32(Int32 value)
        {
            bool ret = true;
            BigInteger bigInteger;

            bigInteger = new BigInteger(value);

            if (!bigInteger.Equals(value))
            {
                Console.WriteLine("Expected BigInteger {0} to be equal to Int32 {1}", bigInteger, value);
                ret = false;
            }
            if (String.CompareOrdinal(value.ToString(), bigInteger.ToString()) != 0)
            {
                Console.WriteLine("Int32.ToString() and BigInteger.ToString() on {0} and {1} should be equal", value, bigInteger);
                ret = false;
            }
            if (value != (Int32)bigInteger)
            {
                Console.WriteLine("Expected BigInteger {0} to be equal to Int32 {1}", bigInteger, value);
                ret = false;
            }

            if (value != Int32.MaxValue)
            {
                if ((Int32)(value + 1) != (Int32)(bigInteger + 1))
                {
                    Console.WriteLine("Adding 1 to both {0} and {1} should remain equal", value, bigInteger);
                    ret = false;
                }
            }

            if (value != Int32.MinValue)
            {
                if ((Int32)(value - 1) != (Int32)(bigInteger - 1))
                {
                    Console.WriteLine("Subtracting 1 from both {0} and {1} should remain equal", value, bigInteger);
                    ret = false;
                }
            }

            Assert.True(VerifyBigintegerUsingIdentities(bigInteger, 0 == value), " Verification Failed");

            return ret;
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:45,代码来源:ctor.cs

示例7: GenerateBlindingFactor

		/**
		* Generate a suitable blind factor for the public key the generator was initialised with.
		*
		* @return a random blind factor
		*/
		public BigInteger GenerateBlindingFactor()
		{
			if (key == null)
				throw new InvalidOperationException("generator not initialised");

			BigInteger m = key.Modulus;
			int length = m.BitLength - 1; // must be less than m.BitLength
			BigInteger factor;
			BigInteger gcd;

			do
			{
				factor = new BigInteger(length, random);
				gcd = factor.Gcd(m);
			}
			while (factor.Sign == 0 || factor.Equals(BigInteger.One) || !gcd.Equals(BigInteger.One));

			return factor;
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:24,代码来源:RSABlindingFactorGenerator.cs

示例8: Equals_BI_on_same_is_true

 public void Equals_BI_on_same_is_true()
 {
     BigInteger i = new BigInteger(1, 0x1, 0x2, 0x3);
     BigInteger j = new BigInteger(1, 0x1, 0x2, 0x3);
     Expect(i.Equals(j));
 }
开发者ID:richhickey,项目名称:clojure-clr,代码行数:6,代码来源:BigIntegerTests.cs

示例9: BIDivide

        public static object BIDivide(BigInteger n, BigInteger d)
        {
            if (d.Equals(BigInteger.ZERO))
                throw new ArithmeticException("Divide by zero");
            //BigInteger gcd = n.gcd(d);
            BigInteger gcd = n.Gcd(d);
            if (gcd.Equals(BigInteger.ZERO))
                return 0;
            //n = n.divide(gcd);
            //d = d.divide(gcd);
            n = n / gcd;
            d = d / gcd;

            if (d.Equals(BigInteger.ONE))
                return reduce(n);
            //return new Ratio((d.signum() < 0 ? n.negate() : n),
            //    (d.signum() < 0 ? d.negate() : d));
            return new Ratio((d.Signum < 0 ? -n : n), d.Abs());
        }
开发者ID:jlomax,项目名称:clojure-clr,代码行数:19,代码来源:NumbersV0.cs

示例10: Equals_BI_on_different_is_false

 public void Equals_BI_on_different_is_false()
 {
     BigInteger i = new BigInteger(1, 0x1, 0x2, 0x3);
     BigInteger j = new BigInteger(1, 0x1, 0x2, 0x4);
     Expect(i.Equals(j),False);
 }
开发者ID:richhickey,项目名称:clojure-clr,代码行数:6,代码来源:BigIntegerTests.cs

示例11: Equals_BI_on_null_is_false

 public void Equals_BI_on_null_is_false()
 {
     BigInteger i = new BigInteger(1, 0x1, 0x2, 0x3);
     Expect(i.Equals(null), False);
 }
开发者ID:richhickey,项目名称:clojure-clr,代码行数:5,代码来源:BigIntegerTests.cs

示例12: NextProbablePrime

        /// <summary>
        /// Compute the next probable prime greater than <c>N</c> with the specified certainty
        /// </summary>
        /// 
        /// <param name="X">An integer number</param>
        /// <param name="Certainty">The certainty that the generated number is prime</param>
        /// 
        /// <returns>Returns the next prime greater than <c>N</c></returns>
        public static BigInteger NextProbablePrime(BigInteger X, int Certainty)
        {
            if (X.Signum() < 0 || X.Signum() == 0 || X.Equals(ONE))
                return TWO;

            BigInteger result = X.Add(ONE);

            // Ensure an odd number
            if (!result.TestBit(0))
                result = result.Add(ONE);

            while (true)
            {
                // Do cheap "pre-test" if applicable
                if (result.BitLength > 6)
                {
                    long r = result.Remainder(BigInteger.ValueOf(SMALL_PRIME_PRODUCT)).ToInt64();
                    if ((r % 3 == 0) || (r % 5 == 0) || (r % 7 == 0) ||
                        (r % 11 == 0) || (r % 13 == 0) || (r % 17 == 0) ||
                        (r % 19 == 0) || (r % 23 == 0) || (r % 29 == 0) ||
                        (r % 31 == 0) || (r % 37 == 0) || (r % 41 == 0))
                    {
                        result = result.Add(TWO);
                        continue; // Candidate is composite; try another
                    }
                }

                // All candidates of bitLength 2 and 3 are prime by this point
                if (result.BitLength < 4)
                    return result;

                // The expensive test
                if (result.IsProbablePrime(Certainty))
                    return result;

                result = result.Add(TWO);
            }
        }
开发者ID:Steppenwolfe65,项目名称:Rainbow-NET,代码行数:46,代码来源:BigMath.cs

示例13: EqualsTest3

 public void EqualsTest3()
 {
     BigInteger target = new BigInteger(); // TODO: Initialize to an appropriate value
     long other = 0; // TODO: Initialize to an appropriate value
     bool expected = false; // TODO: Initialize to an appropriate value
     bool actual;
     actual = target.Equals(other);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
开发者ID:pecegit,项目名称:sshnet,代码行数:10,代码来源:BigIntegerTest.cs

示例14: VerifyComparison

        private static void VerifyComparison(BigInteger x, bool IsXNegative, BigInteger y, bool IsYNegative, int expectedResult)
        {
            bool expectedEquals = 0 == expectedResult;
            bool expectedLessThan = expectedResult < 0;
            bool expectedGreaterThan = expectedResult > 0;

            if (IsXNegative == true)
            {
                x = x * -1;
            }
            if (IsYNegative == true)
            {
                y = y * -1;
            }

            Assert.Equal(expectedEquals, x == y);
            Assert.Equal(expectedEquals, y == x);

            Assert.Equal(!expectedEquals, x != y);
            Assert.Equal(!expectedEquals, y != x);

            Assert.Equal(expectedEquals, x.Equals(y));
            Assert.Equal(expectedEquals, y.Equals(x));

            Assert.Equal(expectedEquals, x.Equals((Object)y));
            Assert.Equal(expectedEquals, y.Equals((Object)x));

            VerifyCompareResult(expectedResult, x.CompareTo(y), "x.CompareTo(y)");
            VerifyCompareResult(-expectedResult, y.CompareTo(x), "y.CompareTo(x)");

            if (expectedEquals)
            {
                Assert.Equal(x.GetHashCode(), y.GetHashCode());
                Assert.Equal(x.ToString(), y.ToString());
            }

            Assert.Equal(x.GetHashCode(), x.GetHashCode());
            Assert.Equal(y.GetHashCode(), y.GetHashCode());

            Assert.Equal(expectedLessThan, x < y);
            Assert.Equal(expectedGreaterThan, y < x);

            Assert.Equal(expectedGreaterThan, x > y);
            Assert.Equal(expectedLessThan, y > x);

            Assert.Equal(expectedLessThan || expectedEquals, x <= y);
            Assert.Equal(expectedGreaterThan || expectedEquals, y <= x);

            Assert.Equal(expectedGreaterThan || expectedEquals, x >= y);
            Assert.Equal(expectedLessThan || expectedEquals, y >= x);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:51,代码来源:Comparison.cs

示例15: Ressol

        /// <summary>
        /// Computes the square root of a BigInteger modulo a prime employing the Shanks-Tonelli algorithm
        /// </summary>
        /// 
        /// <param name="X">The value out of which we extract the square root</param>
        /// <param name="P">The prime modulus that determines the underlying field</param>
        /// 
        /// <returns>Returns a number <c>B</c> such that B^2 = A (mod P) if <c>A</c> is a quadratic residue modulo <c>P</c></returns>
        public static BigInteger Ressol(BigInteger X, BigInteger P)
        {
            BigInteger v = null;

            if (X.CompareTo(ZERO) < 0)
                X = X.Add(P);
            if (X.Equals(ZERO))
                return ZERO;
            if (P.Equals(TWO))
                return X;

            // p = 3 mod 4
            if (P.TestBit(0) && P.TestBit(1))
            {
                if (Jacobi(X, P) == 1)
                {
                    // a quadr. residue mod p
                    v = P.Add(ONE); // v = p+1
                    v = v.ShiftRight(2); // v = v/4
                    return X.ModPow(v, P); // return a^v mod p
                }
                throw new ArgumentException("No quadratic residue: " + X + ", " + P);
            }

            long t = 0;

            // initialization
            // compute k and s, where p = 2^s (2k+1) +1

            BigInteger k = P.Subtract(ONE); // k = p-1
            long s = 0;
            while (!k.TestBit(0))
            { // while k is even
                s++; // s = s+1
                k = k.ShiftRight(1); // k = k/2
            }

            k = k.Subtract(ONE); // k = k - 1
            k = k.ShiftRight(1); // k = k/2

            // initial values
            BigInteger r = X.ModPow(k, P); // r = a^k mod p

            BigInteger n = r.Multiply(r).Remainder(P); // n = r^2 % p
            n = n.Multiply(X).Remainder(P); // n = n * a % p
            r = r.Multiply(X).Remainder(P); // r = r * a %p

            if (n.Equals(ONE))
            {
                return r;
            }

            // non-quadratic residue
            BigInteger z = TWO; // z = 2
            while (Jacobi(z, P) == 1)
            {
                // while z quadratic residue
                z = z.Add(ONE); // z = z + 1
            }

            v = k;
            v = v.Multiply(TWO); // v = 2k
            v = v.Add(ONE); // v = 2k + 1
            BigInteger c = z.ModPow(v, P); // c = z^v mod p

            // iteration
            while (n.CompareTo(ONE) == 1)
            { // n > 1
                k = n; // k = n
                t = s; // t = s
                s = 0;

                while (!k.Equals(ONE))
                { // k != 1
                    k = k.Multiply(k).Mod(P); // k = k^2 % p
                    s++; // s = s + 1
                }

                t -= s; // t = t - s
                if (t == 0)
                {
                    throw new ArgumentException("No quadratic residue: " + X + ", " + P);
                }

                v = ONE;
                for (long i = 0; i < t - 1; i++)
                {
                    v = v.ShiftLeft(1); // v = 1 * 2^(t - 1)
                }
                c = c.ModPow(v, P); // c = c^v mod p
                r = r.Multiply(c).Remainder(P); // r = r * c % p
                c = c.Multiply(c).Remainder(P); // c = c^2 % p
//.........这里部分代码省略.........
开发者ID:Steppenwolfe65,项目名称:Rainbow-NET,代码行数:101,代码来源:BigMath.cs


注:本文中的BigInteger.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。