當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。