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


C# BigInteger.DivideAndRemainder方法代码示例

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


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

示例1: H1hash

        public static BigInteger H1hash(string ID, BigInteger p)
        {
            // H1 je sha256(ID) mod p
            SHA256Managed crypt = new SHA256Managed();
            StringBuilder hash = new StringBuilder();
            byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(ID), 0, Encoding.UTF8.GetByteCount(ID));
            foreach (byte theByte in crypto)
            {
                hash.Append(theByte.ToString("x2"));
            }

            BigInteger hsh = new BigInteger(hash.ToString(), 16);
            // hash mod p
            BigInteger x = hsh.DivideAndRemainder(p)[1];

            return x;
        }
开发者ID:excrucio,项目名称:ibe,代码行数:17,代码来源:GeneralFunctions.cs

示例2: H2hash

        public static string H2hash(BigInteger qid, BigInteger p)
        {
            // H2 je RiPEMD-120: točka iz polja -> niz bita mod p
            string tocka = qid.ToString();

            RIPEMD160Managed crypt = new RIPEMD160Managed();
            StringBuilder hash = new StringBuilder();
            byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(tocka), 0, Encoding.UTF8.GetByteCount(tocka));
            foreach (byte theByte in crypto)
            {
                hash.Append(theByte.ToString("x2"));
            }

            BigInteger hsh = new BigInteger(hash.ToString(), 16);
            // hash mod n
            BigInteger c = hsh.DivideAndRemainder(p)[1];

            return c.ToString();
        }
开发者ID:excrucio,项目名称:ibe,代码行数:19,代码来源:GeneralFunctions.cs

示例3: Encode

        public string Encode(byte[] input)
        {
            // Decode byte[] to BigInteger
            BigInteger intData=new BigInteger(1,input);

            // Encode BigInteger to Base string
            string result=string.Empty;
            while(intData.CompareTo(0)>0)
            {
                BigInteger[] divide=intData.DivideAndRemainder(Base);
                intData=divide[0];
                result=Alphabet[divide[1].IntValue]+result;
            }

            // Append `1` for each leading 0 byte
            for(int i=0;i<input.Length && input[i]==0;i++)
            { result=Alphabet[0]+result; }
            return result;
        }
开发者ID:knocte,项目名称:BitcoinDotNet,代码行数:19,代码来源:BaseChanger.cs

示例4: TestDivideAndRemainder

		public void TestDivideAndRemainder()
		{
			// TODO More basic tests

			BigInteger n = new BigInteger(48, random);
			BigInteger[] qr = n.DivideAndRemainder(one);
			Assert.AreEqual(n, qr[0]);
			Assert.AreEqual(zero, qr[1]);

			for (int rep = 0; rep < 10; ++rep)
			{
				BigInteger a = new BigInteger(100 - rep, 0, random);
				BigInteger b = new BigInteger(100 + rep, 0, random);
				BigInteger c = new BigInteger(10 + rep, 0, random);
				BigInteger d = a.Multiply(b).Add(c);
				BigInteger[] es = d.DivideAndRemainder(a);

				Assert.AreEqual(b, es[0]);
				Assert.AreEqual(c, es[1]);
			}

			// Special tests for power of two since uses different code path internally
			for (int i = 0; i < 100; ++i)
			{
				int shift = random.Next(64);
				BigInteger a = one.ShiftLeft(shift);
				BigInteger b = new BigInteger(64 + random.Next(64), random);
				BigInteger bShift = b.ShiftRight(shift);
				BigInteger bMod = b.And(a.Subtract(one));

				string data = "shift=" + shift +", b=" + b.ToString(16);

				qr = b.DivideAndRemainder(a);
				Assert.AreEqual(bShift, qr[0], data);
				Assert.AreEqual(bMod, qr[1], data);

				qr = b.DivideAndRemainder(a.Negate());
				Assert.AreEqual(bShift.Negate(), qr[0], data);
				Assert.AreEqual(bMod, qr[1], data);

				qr = b.Negate().DivideAndRemainder(a);
				Assert.AreEqual(bShift.Negate(), qr[0], data);
				Assert.AreEqual(bMod.Negate(), qr[1], data);

				qr = b.Negate().DivideAndRemainder(a.Negate());
				Assert.AreEqual(bShift, qr[0], data);
				Assert.AreEqual(bMod.Negate(), qr[1], data);
			}
		}
开发者ID:randombit,项目名称:hacrypto,代码行数:49,代码来源:BigIntegerTest.cs


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