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


C# BigInteger类代码示例

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


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

示例1: Main

    static void Main()
    {
        Console.Write("vavedi N:");
        int numberN = int.Parse(Console.ReadLine());
        Console.Write("vavedi K:");
        int numberK = int.Parse(Console.ReadLine());

        if (numberN > 1 && numberK > numberN)
        {
            var factorialN = new BigInteger(1);
            for (var i = 1; i <= numberN; i++)
            {
                factorialN *= i;
            }
            Console.WriteLine("Factorial n = {0}", factorialN);

            var factorialK = new BigInteger(1);
            for (var j = 1; j <= numberK; j++)
            {
                factorialK *= j;
            }
            Console.WriteLine("Factorial k = {0}", factorialK);

            var nAndK = new BigInteger(1);
            nAndK = factorialN/factorialK;
            Console.WriteLine("N!/K!={0}", nAndK);
        }
        else
        {
            Console.WriteLine("N > 1 and K > N");
        }
    }
开发者ID:EagleTA,项目名称:TelerikAcademy,代码行数:32,代码来源:NAndKFactorials.cs

示例2: RsaPublicBcpgKey

		/// <param name="n">The modulus.</param>
		/// <param name="e">The public exponent.</param>
		public RsaPublicBcpgKey(
			BigInteger	n,
			BigInteger	e)
		{
			this.n = new MPInteger(n);
			this.e = new MPInteger(e);
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:9,代码来源:RsaPublicBcpgKey.cs

示例3: IsPrime

 static bool IsPrime(BigInteger n)
 {
     bool isPrime = true;
     if(n==0||n==1)
     {
         return false;
     }
     else if(n==2||n==3)
     {
         return true;
     }
     else if(n<100&&n>3)
     {
         for(int s=2;s<n;s++)
         {
             if (n % s == 0)
                 isPrime = false;
         }
         return isPrime;
     }
     else
     {
         for (BigInteger i = 3; (i * i) <= n; i+=2)
         {
             if (n%i==0)
             {
                 isPrime = false;
                 break;
             }
         }
         return isPrime;
     }
 }
开发者ID:hristolilov,项目名称:SoftUni,代码行数:33,代码来源:PrimeChecker.cs

示例4: GenerateSearchBase

		protected override BigInteger GenerateSearchBase (int bits, object Context) 
		{
			if (Context == null) throw new ArgumentNullException ("Context");
			BigInteger ret = new BigInteger ((BigInteger)Context);
			ret.setBit (0);
			return ret;
		}
开发者ID:svn2github,项目名称:SSIS-Extensions,代码行数:7,代码来源:NextPrimeFinder.cs

示例5: ShamirsTrick

        /*
        * "Shamir's Trick", originally due to E. G. Straus
        * (Addition chains of vectors. American Mathematical Monthly,
        * 71(7):806-808, Aug./Sept. 1964)
        *
        * Input: The points P, Q, scalar k = (km?, ... , k1, k0)
        * and scalar l = (lm?, ... , l1, l0).
        * Output: R = k * P + l * Q.
        * 1: Z <- P + Q
        * 2: R <- O
        * 3: for i from m-1 down to 0 do
        * 4:        R <- R + R        {point doubling}
        * 5:        if (ki = 1) and (li = 0) then R <- R + P end if
        * 6:        if (ki = 0) and (li = 1) then R <- R + Q end if
        * 7:        if (ki = 1) and (li = 1) then R <- R + Z end if
        * 8: end for
        * 9: return R
        */
        public static ECPoint ShamirsTrick(ECPoint p, BigInteger k, ECPoint q, BigInteger l)
        {
            if (!p.Curve.Equals(q.Curve))
                throw new ArgumentException("P and Q must be on same curve");

            return ImplShamirsTrick(p, k, q, l);
        }
开发者ID:sanyaade-iot,项目名称:Schmoose-BouncyCastle,代码行数:25,代码来源:ECAlgorithms.cs

示例6: SetupCrypto

        public void SetupCrypto(BigInteger key)
        {
            byte[] ServerDecryptionKey =
            {
                0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5,
                0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE
            };

            byte[] ServerEncryptionKey =
            {
                0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA,
                0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57
            };

            HMACSHA1 decryptHMAC = new HMACSHA1(ServerDecryptionKey);
            HMACSHA1 encryptHMAC = new HMACSHA1(ServerEncryptionKey);

            var decryptHash = decryptHMAC.ComputeHash(key.GetBytes());
            var encryptHash = encryptHMAC.ComputeHash(key.GetBytes());

            const int dropN = 1024; //1000 before WoTLK, 1024 now
            var buf = new byte[dropN];

            ClientConnection.Decrypt = new ARC4(decryptHash);
            ClientConnection.Encrypt = new ARC4(encryptHash);

            ClientConnection.Decrypt.Process(buf, 0, buf.Length);
            ClientConnection.Encrypt.Process(buf, 0, buf.Length);
        }
开发者ID:andy012345,项目名称:WoWServer,代码行数:29,代码来源:RealmPacketHandler.cs

示例7: AdditionIsCommutative

        public void AdditionIsCommutative()
        {
            var a = new BigInteger("2342452452435235098091834098018");
            var b = new BigInteger("102938209095450980895402985098560727234098123345");

            Assert.AreEqual(a + b, b + a);
        }
开发者ID:davghouse,项目名称:SPOJ,代码行数:7,代码来源:BigIntegerTests.cs

示例8: SetPublic

 public void SetPublic(string modulus, string exponent)
 {
     if (string.IsNullOrEmpty(modulus) || string.IsNullOrEmpty(exponent))
         throw new Exception("Invalid RSA public key");
     Modulus = new BigInteger(modulus, 16);
     Exponent = new BigInteger(exponent, 16);
 }
开发者ID:KribKing,项目名称:imitate-login,代码行数:7,代码来源:RSAHelper.cs

示例9: CalculateScore

    private static BigInteger CalculateScore(int heigth, int width, int[] moves, BigInteger[][] matrix)
    {
        BigInteger sumVisited = 0;
        int coeficient = Math.Max(heigth, width);
        int posX = 0;
        int posY = heigth - 1;
        for (int i = 0; i < moves.GetLength(0); i++)
        {
            int moveToX = moves[i] % coeficient;
            int moveToY = moves[i] / coeficient;

            int walkXFrom = Math.Min(moveToX, posX);
            int walkXTo = Math.Max(moveToX, posX);
            for (int j = walkXFrom; j <= walkXTo; j++)
            {
                sumVisited += matrix[posY][j];
                matrix[posY][j] = 0;
            }

            posX = moveToX;

            int walkYFrom = Math.Min(moveToY, posY);
            int walkYTo = Math.Max(moveToY, posY);
            for (int j = walkYFrom; j <= walkYTo; j++)
            {
                sumVisited += matrix[j][posX];
                matrix[j][posX] = 0;
            }

            posY = moveToY;
        }

        return sumVisited;
    }
开发者ID:damy90,项目名称:Telerik-all,代码行数:34,代码来源:BitShiftMatrix.cs

示例10: BitCount

        /// <summary>
        /// Returns the number of bits in the binary representation of this which differ from the sign bit. 
        /// <para>Use BitLength(0) if you want to know the length of the binary value in bits.
        /// If this is positive the result is equivalent to the number of bits set in the binary representation of this.
        /// If this is negative the result is equivalent to the number of bits set in the binary representation of -this - 1.</para>
        /// </summary>
        internal static int BitCount(BigInteger Value)
        {
            int bCount = 0;

            if (Value._sign == 0)
                return 0;

            int i = Value.FirstNonzeroDigit; ;
            if (Value._sign > 0)
            {
                for (; i < Value._numberLength; i++)
                    bCount += IntUtils.BitCount(Value._digits[i]);
            }
            else
            {
                // this digit absorbs the carry
                bCount += IntUtils.BitCount(-Value._digits[i]);

                for (i++; i < Value._numberLength; i++)
                    bCount += IntUtils.BitCount(~Value._digits[i]);

                // We take the complement sum:
                bCount = (Value._numberLength << 5) - bCount;
            }
            return bCount;
        }
开发者ID:DeadlyEmbrace,项目名称:NTRU-NET,代码行数:32,代码来源:BitLevel.cs

示例11: Main

    static void Main()
    {
        Console.WriteLine("How many digits will contain the first number ?");
        int lengthOne = int.Parse(Console.ReadLine());
        BigInteger[] numberOne = new BigInteger[lengthOne];
        Console.WriteLine("Enter the digits of the number");
        for (int i = lengthOne - 1; i > -1; i--)
        {
            numberOne[i] = BigInteger.Parse(Console.ReadLine());
        }

        Console.WriteLine("How many digits will contain the second number ?");
        int lengthTwo = int.Parse(Console.ReadLine());
        BigInteger[] numberTwo = new BigInteger[lengthTwo];
        Console.WriteLine("Enter the digits of the number");
        for (int i = lengthTwo - 1; i > -1; i--)
        {
            numberTwo[i] = BigInteger.Parse(Console.ReadLine());
        }

        BigInteger[] sum = SumNumber(numberOne, numberTwo);

        Console.WriteLine();
        foreach (BigInteger i in sum)
        {
            Console.Write(i);
        }
    }
开发者ID:huuuskyyy,项目名称:CSharp-Homeworks,代码行数:28,代码来源:08.+AddIntegers.cs

示例12: DHParameters

		public DHParameters(
			BigInteger	p,
			BigInteger	g,
			BigInteger	q)
			: this(p, g, q, 0)
		{
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:7,代码来源:DHParameters.cs

示例13: CheckNumForNull

 private static void CheckNumForNull(BigInteger[] array, int targetIndex)
 {
     if (array[targetIndex] < 0)
     {
         array[targetIndex] = 0;
     }
 }
开发者ID:Bstoyanov,项目名称:C-AdvancedExamProblems,代码行数:7,代码来源:ArraySlider.cs

示例14: Multiply

		/**
		* D.3.2 pg 101
		* @see org.bouncycastle.math.ec.multiplier.ECMultiplier#multiply(org.bouncycastle.math.ec.ECPoint, java.math.BigInteger)
		*/
		public ECPoint Multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
		{
			// TODO Probably should try to add this
			// BigInteger e = k.Mod(n); // n == order of p
			BigInteger e = k;
			BigInteger h = e.Multiply(BigInteger.Three);

			ECPoint neg = p.Negate();
			ECPoint R = p;

			for (int i = h.BitLength - 2; i > 0; --i)
			{             
				R = R.Twice();

				bool hBit = h.TestBit(i);
				bool eBit = e.TestBit(i);

				if (hBit != eBit)
				{
					R = R.Add(hBit ? p : neg);
				}
			}

			return R;
		}
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:29,代码来源:FpNafMultiplier.cs

示例15: ArrToNumber

 //converts an array, whose index 0 is the last digit of a number, to the number.
 static BigInteger ArrToNumber(BigInteger[] arr)
 {
     Array.Reverse(arr);
     string numberString = string.Join("", arr);
     BigInteger result = BigInteger.Parse(numberString);
     return result;
 }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:8,代码来源:NumbersasArray.cs


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