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


C# BigInteger.bitCount方法代码示例

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


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

示例1: Initialize

		// initializes the private variables (throws CryptographicException)
		private void Initialize(BigInteger p, BigInteger g, BigInteger x, int secretLen, bool checkInput) {
			if (!p.isProbablePrime() || g <= 0 || g >= p || (x != null && (x <= 0 || x > p - 2)))
				throw new CryptographicException();
			// default is to generate a number as large as the prime this
			// is usually overkill, but it's the most secure thing we can
			// do if the user doesn't specify a desired secret length ...
			if (secretLen == 0)
				secretLen = p.bitCount();
			m_P = p;
			m_G = g;
			if (x == null) {
				BigInteger pm1 = m_P - 1;
				for(m_X = BigInteger.genRandom(secretLen); m_X >= pm1 || m_X == 0; m_X = BigInteger.genRandom(secretLen)) {}
			} else {
				m_X = x;
			}
		}
开发者ID:svn2github,项目名称:SSIS-Extensions,代码行数:18,代码来源:DiffieHellmanManaged.cs

示例2: EvenPow

            public BigInteger EvenPow(BigInteger b, BigInteger exp)
            {
                BigInteger resultNum = new BigInteger((BigInteger)1, mod.length << 1);
                BigInteger tempNum = new BigInteger(b % mod, mod.length << 1);  // ensures (tempNum * tempNum) < b^ (2k)

                uint totalBits = (uint)exp.bitCount();

                uint[] wkspace = new uint[mod.length << 1];

                // perform squaring and multiply exponentiation
                for (uint pos = 0; pos < totalBits; pos++)
                {
                    if (exp.testBit(pos))
                    {

                        Array.Clear(wkspace, 0, wkspace.Length);
                        Kernel.Multiply(resultNum.data, 0, resultNum.length, tempNum.data, 0, tempNum.length, wkspace, 0);
                        resultNum.length += tempNum.length;
                        uint[] t = wkspace;
                        wkspace = resultNum.data;
                        resultNum.data = t;

                        BarrettReduction(resultNum);
                    }

                    Kernel.SquarePositive(tempNum, ref wkspace);
                    BarrettReduction(tempNum);

                    if (tempNum == 1)
                    {
                        return resultNum;
                    }
                }

                return resultNum;
            }
开发者ID:JamesHagerman,项目名称:sftprelay,代码行数:36,代码来源:BigInteger.cs

示例3: OddModTwoPow

            private unsafe BigInteger OddModTwoPow(BigInteger exp)
            {

                uint[] wkspace = new uint[mod.length << 1 + 1];

                BigInteger resultNum = Montgomery.ToMont((BigInteger)2, this.mod);
                resultNum = new BigInteger(resultNum, mod.length << 1 + 1);

                uint mPrime = Montgomery.Inverse(mod.data[0]);

                //
                // TODO: eat small bits, the ones we can do with no modular reduction
                //
                uint pos = (uint)exp.bitCount() - 2;

                do
                {
                    Kernel.SquarePositive(resultNum, ref wkspace);
                    resultNum = Montgomery.Reduce(resultNum, mod, mPrime);

                    if (exp.testBit(pos))
                    {
                        //
                        // resultNum = (resultNum * 2) % mod
                        //

                        fixed (uint* u = resultNum.data)
                        {
                            //
                            // Double
                            //
                            uint* uu = u;
                            uint* uuE = u + resultNum.length;
                            uint x, carry = 0;
                            while (uu < uuE)
                            {
                                x = *uu;
                                *uu = (x << 1) | carry;
                                carry = x >> (32 - 1);
                                uu++;
                            }

                            // subtraction inlined because we know it is square
                            if (carry != 0 || resultNum >= mod)
                            {
                                fixed (uint* s = mod.data)
                                {
                                    uu = u;
                                    uint c = 0;
                                    uint* ss = s;
                                    do
                                    {
                                        uint a = *ss++;
                                        if (((a += c) < c) | ((*(uu++) -= a) > ~a))
                                            c = 1;
                                        else
                                            c = 0;
                                    } while (uu < uuE);
                                }
                            }
                        }
                    }
                } while (pos-- > 0);

                resultNum = Montgomery.Reduce(resultNum, mod, mPrime);
                return resultNum;
            }
开发者ID:JamesHagerman,项目名称:sftprelay,代码行数:67,代码来源:BigInteger.cs

示例4: OddPow

            private BigInteger OddPow(BigInteger b, BigInteger exp)
            {
                BigInteger resultNum = new BigInteger(Montgomery.ToMont(1, mod), mod.length << 1);
                BigInteger tempNum = new BigInteger(Montgomery.ToMont(b, mod), mod.length << 1);  // ensures (tempNum * tempNum) < b^ (2k)
                uint mPrime = Montgomery.Inverse(mod.data[0]);
                uint totalBits = (uint)exp.bitCount();

                uint[] wkspace = new uint[mod.length << 1];

                // perform squaring and multiply exponentiation
                for (uint pos = 0; pos < totalBits; pos++)
                {
                    if (exp.testBit(pos))
                    {

                        Array.Clear(wkspace, 0, wkspace.Length);
                        Kernel.Multiply(resultNum.data, 0, resultNum.length, tempNum.data, 0, tempNum.length, wkspace, 0);
                        resultNum.length += tempNum.length;
                        uint[] t = wkspace;
                        wkspace = resultNum.data;
                        resultNum.data = t;

                        Montgomery.Reduce(resultNum, mod, mPrime);
                    }

                    Kernel.SquarePositive(tempNum, ref wkspace);
                    Montgomery.Reduce(tempNum, mod, mPrime);
                }

                Montgomery.Reduce(resultNum, mod, mPrime);
                return resultNum;
            }
开发者ID:JamesHagerman,项目名称:sftprelay,代码行数:32,代码来源:BigInteger.cs

示例5: Initialize

        private void Initialize(BigInteger p, BigInteger g, BigInteger x)
        {
            if (!p.isProbablePrime() || g <= 0 || g >= p)
                throw new CryptographicException("Inputs p or g are not as expected. P probably isn't a prime or G is less than zero or more than P.");

            if(x != null) {
                _x = x;
            } else {
                var pMinus1 = p - 1;
                var secretLen = p.bitCount();
                for (_x = BigInteger.genRandom(secretLen); _x >= pMinus1 || _x == 0; _x = BigInteger.genRandom(secretLen)) { }
            }

            _p = p;
            _g = g;
        }
开发者ID:rackerlabs,项目名称:openstack-guest-agents-windows-xenserver-old,代码行数:16,代码来源:DiffieHellmanManaged.cs


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