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


C# IBigInteger.CompareTo方法代码示例

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


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

示例1: CreateRandomInRange

        /**
        * Return a random IBigInteger not less than 'min' and not greater than 'max'
        *
        * @param min the least value that may be generated
        * @param max the greatest value that may be generated
        * @param random the source of randomness
        * @return a random IBigInteger value in the range [min,max]
        */
        public static IBigInteger CreateRandomInRange(
            IBigInteger min,
            IBigInteger max,
			// TODO Should have been just Random class
			ISecureRandom	random)
        {
            int cmp = min.CompareTo(max);
            if (cmp >= 0)
            {
                if (cmp > 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 < MaxIterations; ++i)
            {
                IBigInteger x = new BigInteger(max.BitLength, random);
                if (x.CompareTo(min) >= 0 && x.CompareTo(max) <= 0)
                {
                    return x;
                }
            }

            // fall back to a faster (restricted) method
            return new BigInteger(max.Subtract(min).BitLength - 1, random).Add(min);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:40,代码来源:BigIntegers.cs

示例2: FPFieldElement

        /// <summary>
        /// Initializes a new instance of the <see cref="FPFieldElement"/> class.
        /// </summary>
        /// <param name="q">The q.</param>
        /// <param name="x">The x.</param>
        /// <exception cref="System.ArgumentException">x value too large in field element</exception>
        public FPFieldElement(IBigInteger q, IBigInteger x)
        {
            if (x.CompareTo(q) >= 0)
                throw new ArgumentException("x value too large in field element");

            _q = q;
            _x = x;
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:14,代码来源:FPFieldElement.cs

示例3: Gost3410PrivateKeyParameters

        public Gost3410PrivateKeyParameters(
            IBigInteger x,
			DerObjectIdentifier	publicKeyParamSet)
            : base(true, publicKeyParamSet)
        {
            if (x.SignValue < 1 || x.BitLength > 256 || x.CompareTo(Parameters.Q) >= 0)
                throw new ArgumentException(@"Invalid x for GOST3410 private key", "x");

            this.x = x;
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:10,代码来源:GOST3410PrivateKeyParameters.cs

示例4: Gost3410PublicKeyParameters

        public Gost3410PublicKeyParameters(
            IBigInteger y,
			DerObjectIdentifier publicKeyParamSet)
            : base(false, publicKeyParamSet)
        {
            if (y.SignValue < 1 || y.CompareTo(Parameters.P) >= 0)
                throw new ArgumentException(@"Invalid y for GOST3410 public key", "y");

            this.y = y;
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:10,代码来源:GOST3410PublicKeyParameters.cs

示例5: DHParameters

        public DHParameters(
            IBigInteger p,
            IBigInteger g,
            IBigInteger q,
			int						m,
			int						l,
            IBigInteger j,
			DHValidationParameters	validation)
        {
            if (p == null)
                throw new ArgumentNullException("p");
            if (g == null)
                throw new ArgumentNullException("g");
            if (!p.TestBit(0))
                throw new ArgumentException(@"field must be an odd prime", "p");
            if (g.CompareTo(BigInteger.Two) < 0
                || g.CompareTo(p.Subtract(BigInteger.Two)) > 0)
                throw new ArgumentException(@"generator must in the range [2, p - 2]", "g");
            if (q != null && q.BitLength >= p.BitLength)
                throw new ArgumentException(@"q too big to be a factor of (p-1)", "q");
            if (m >= p.BitLength)
                throw new ArgumentException(@"m value must be < bitlength of p", "m");
            if (l != 0)
            {
                if (l >= p.BitLength)
                    throw new ArgumentException(@"when l value specified, it must be less than bitlength(p)", "l");
                if (l < m)
                    throw new ArgumentException(@"when l value specified, it may not be less than m value", "l");
            }
            if (j != null && j.CompareTo(BigInteger.Two) < 0)
                throw new ArgumentException(@"subgroup factor must be >= 2", "j");

            // TODO If q, j both provided, validate p = jq + 1 ?

            this.p = p;
            this.g = g;
            this.q = q;
            this.m = m;
            this.l = l;
            this.j = j;
            this.validation = validation;
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:42,代码来源:DHParameters.cs

示例6: RsaSecretBcpgKey

        public RsaSecretBcpgKey(IBigInteger d, IBigInteger p, IBigInteger q)
        {
            // PGP requires (p < q)
            var cmp = p.CompareTo(q);
            if (cmp >= 0)
            {
                if (cmp == 0)
                    throw new ArgumentException("p and q cannot be equal");

                var tmp = p;
                p = q;
                q = tmp;
            }

            _d = new MPInteger(d);
            _p = new MPInteger(p);
            _q = new MPInteger(q);
            _u = new MPInteger(p.ModInverse(q));

            _expP = d.Remainder(p.Subtract(BigInteger.One));
            _expQ = d.Remainder(q.Subtract(BigInteger.One));
            _crt = q.ModInverse(p);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:23,代码来源:RsaSecretBcpgKey.cs

示例7: VerifySignature

        // 5.4 pg 29
        /**
         * return true if the value r and s represent a DSA signature for
         * the passed in message (for standard DSA the message should be
         * a SHA-1 hash of the real message to be verified).
         */
        public bool VerifySignature(byte[] message, IBigInteger r, IBigInteger s)
        {
            var n = _key.Parameters.N;

            // r and s should both in the range [1,n-1]
            if (r.SignValue < 1 || s.SignValue < 1 || r.CompareTo(n) >= 0 || s.CompareTo(n) >= 0)
            {
                return false;
            }

            var e = CalculateE(n, message);
            var c = s.ModInverse(n);

            var u1 = e.Multiply(c).Mod(n);
            var u2 = r.Multiply(c).Mod(n);

            var g = _key.Parameters.G;
            var q = ((ECPublicKeyParameters)_key).Q;

            var point = ECAlgorithms.SumOfTwoMultiplies(g, u1, q, u2);

            var v = point.X.ToBigInteger().Mod(n);
            return v.Equals(r);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:30,代码来源:ECDsaSigner.cs

示例8: VerifySignature

        // Section 7.2.6 ECVP-NR, pg 35
        /**
         * return true if the value r and s represent a signature for the
         * message passed in. Generally, the order of the curve should be at
         * least as long as the hash of the message of interest, and with
         * ECNR, it *must* be at least as long.  But just in case the signer
         * applied mod(n) to the longer digest, this implementation will
         * apply mod(n) during verification.
         *
         * @param digest  the digest to be verified.
         * @param r       the r value of the signature.
         * @param s       the s value of the signature.
         * @exception DataLengthException if the digest is longer than the key allows
         */
        public bool VerifySignature(
			byte[]		message,
            IBigInteger r,
            IBigInteger s)
        {
            if (this._forSigning)
            {
                // not properly initilaized... deal with it
                throw new InvalidOperationException("not initialised for verifying");
            }

            ECPublicKeyParameters pubKey = (ECPublicKeyParameters)_key;
            IBigInteger n = pubKey.Parameters.N;
            int nBitLength = n.BitLength;

            IBigInteger e = new BigInteger(1, message);
            int eBitLength = e.BitLength;

            if (eBitLength > nBitLength)
            {
                throw new DataLengthException("input too large for ECNR key.");
            }

            // r in the range [1,n-1]
            if (r.CompareTo(BigInteger.One) < 0 || r.CompareTo(n) >= 0)
            {
                return false;
            }

            // TODO So why is this different from the spec?
            // s in the range [0,n-1]           NB: ECNR spec says 0
            if (s.CompareTo(BigInteger.Zero) < 0 || s.CompareTo(n) >= 0)
            {
                return false;
            }

            // compute P = sG + rW

            ECPoint G = pubKey.Parameters.G;
            ECPoint W = pubKey.Q;
            // calculate P using Bouncy math
            ECPoint P = ECAlgorithms.SumOfTwoMultiplies(G, s, W, r);

            IBigInteger x = P.X.ToBigInteger();
            IBigInteger t = r.Subtract(x).Mod(n);

            return t.Equals(e);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:62,代码来源:ECNRSigner.cs

示例9: VerifySignature

        /**
         * return true if the value r and s represent a GOST3410 signature for
         * the passed in message (for standard GOST3410 the message should be
         * a GOST3411 hash of the real message to be verified).
         */
        public bool VerifySignature(
			byte[]		message,
            IBigInteger r,
            IBigInteger s)
        {
            byte[] mRev = new byte[message.Length]; // conversion is little-endian
            for (int i = 0; i != mRev.Length; i++)
            {
                mRev[i] = message[mRev.Length - 1 - i];
            }

            IBigInteger e = new BigInteger(1, mRev);
            IBigInteger n = key.Parameters.N;

            // r in the range [1,n-1]
            if (r.CompareTo(BigInteger.One) < 0 || r.CompareTo(n) >= 0)
            {
                return false;
            }

            // s in the range [1,n-1]
            if (s.CompareTo(BigInteger.One) < 0 || s.CompareTo(n) >= 0)
            {
                return false;
            }

            IBigInteger v = e.ModInverse(n);

            IBigInteger z1 = s.Multiply(v).Mod(n);
            IBigInteger z2 = (n.Subtract(r)).Multiply(v).Mod(n);

            ECPoint G = key.Parameters.G; // P
            ECPoint Q = ((ECPublicKeyParameters)key).Q;

            ECPoint point = ECAlgorithms.SumOfTwoMultiplies(G, z1, Q, z2);

            IBigInteger R = point.X.ToBigInteger().Mod(n);

            return R.Equals(r);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:45,代码来源:ECGOST3410Signer.cs


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