• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# BigInteger类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Main

 static void Main()
 {
     Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
     BigInteger q4 = BigInteger.Parse(Console.ReadLine());
     BigInteger q3 = BigInteger.Parse(Console.ReadLine());
     BigInteger q2 = BigInteger.Parse(Console.ReadLine());
     BigInteger q1 = BigInteger.Parse(Console.ReadLine());
     BigInteger nextQNumber = 0;
     BigInteger tempNumber = 0;
     int rows = int.Parse(Console.ReadLine());
     int columns = int.Parse(Console.ReadLine());
     BigInteger[] matrix = new BigInteger[rows * columns];
     matrix [0]= q4;
     matrix [1]= q3;
     matrix [2]= q2;
     matrix [3]= q1;
     for (int i = 4; i < rows*columns; i++)
         {
          matrix [i] = matrix [i-1]+matrix [i-2]+matrix [i-3]+matrix [i-4];
         }
     int counter = 0;
     for (int i = 0; i < rows; i++)
     {
         for (int j = 0; j < columns; j++)
         {
             Console.Write(matrix[counter]);
             Console.Write(" ");
             counter++;
         }
         Console.WriteLine();
     }
 }
开发者ID:velinkoychev,项目名称:Shared,代码行数:32,代码来源:Problem2.cs


示例17: RSAKeyPair

 public RSAKeyPair(BigInteger e, BigInteger d, BigInteger n, BigInteger u, BigInteger p, BigInteger q) {
     _publickey = new RSAPublicKey(e, n);
     _d = d;
     _u = u;
     _p = p;
     _q = q;
 }
开发者ID:PavelTorgashov,项目名称:nfx,代码行数:7,代码来源:RSA.cs


示例18: PortableDigitCount

 private static void PortableDigitCount(BigInteger bi)
 {
     int kb=0;
     if(!bi.IsZero){
       while(true){
     if(bi.CompareTo((BigInteger)Int32.MaxValue)<=0) {
       int tmp = (int)bi;
       while (tmp > 0) {
         kb++;
         tmp /= 10;
       }
       kb=(kb == 0 ? 1 : kb);
       return kb;
     }
     BigInteger q=bi/(BigInteger)bidivisor;
     if(q.IsZero){
       int b=(int)bi;
       while(b>0){
         kb++;
         b/=10;
       }
       break;
     } else {
       kb+=4;
       bi=q;
     }
       }
     } else {
       kb=1;
     }
     return kb;
 }
开发者ID:KSLcom,项目名称:CBOR,代码行数:32,代码来源:CBORObjectPortable.cs


示例19: ZeroPlusZeroIsZero

        public void ZeroPlusZeroIsZero()
        {
            var a = new BigInteger(0);
            var b = new BigInteger("0");

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


示例20: Add_neg_pos_same_mag

 public void Add_neg_pos_same_mag()
 {
     BigInteger x = new BigInteger(-1, new uint[] { 0x3 });
     BigInteger y = new BigInteger(1, new uint[] { 0x3 });
     BigInteger z = x.Add(y);
     Expect(z.IsZero);
 }
开发者ID:richhickey,项目名称:clojure-clr,代码行数:7,代码来源:BigIntegerTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# BigNumber类代码示例发布时间:2022-05-24
下一篇:
C# BigEndianStream类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap