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


C# BigInteger.Multiply方法代码示例

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


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

示例1: GenerateSignature

		/**
		 * generate a signature for the given message using the key we were
		 * initialised with. For conventional Gost3410 the message should be a Gost3411
		 * hash of the message of interest.
		 *
		 * @param message the message that will be verified later.
		 */
		public BigInteger[] GenerateSignature(
			byte[] message)
		{
			byte[] mRev = new byte[message.Length]; // conversion is little-endian
			for (int i = 0; i != mRev.Length; i++)
			{
				mRev[i] = message[mRev.Length - 1 - i];
			}

			BigInteger m = new BigInteger(1, mRev);
			Gost3410Parameters parameters = key.Parameters;
			BigInteger k;

			do
			{
				k = new BigInteger(parameters.Q.BitLength, random);
			}
			while (k.CompareTo(parameters.Q) >= 0);

			BigInteger r = parameters.A.ModPow(k, parameters.P).Mod(parameters.Q);

			BigInteger s = k.Multiply(m).
				Add(((Gost3410PrivateKeyParameters)key).X.Multiply(r)).
				Mod(parameters.Q);

			return new BigInteger[]{ r, s };
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:34,代码来源:GOST3410Signer.cs

示例2: MonoBug81857

        public void MonoBug81857()
        {
            var b = new BigInteger("18446744073709551616");
            var mod = new BigInteger("48112959837082048697");
            var expected = new BigInteger("4970597831480284165");

            BigInteger manual = b.Multiply(b).Mod(mod);
            Assert.AreEqual(expected, manual, "b * b % mod");
        }
开发者ID:ChemicalRocketeer,项目名称:BigMath,代码行数:9,代码来源:BigIntegerTest.cs

示例3: CalculateB

 protected virtual BigInteger CalculateB(BigInteger k, BigInteger g, int t)
 {
     bool negative = (g.SignValue < 0);
     BigInteger b = k.Multiply(g.Abs());
     bool extra = b.TestBit(t - 1);
     b = b.ShiftRight(t);
     if (extra)
     {
         b = b.Add(BigInteger.One);
     }
     return negative ? b.Negate() : b;
 }
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:12,代码来源:GlvTypeBEndomorphism.cs

示例4: ModMult

 protected virtual BigInteger ModMult(BigInteger x1, BigInteger x2)
 {
     return ModReduce(x1.Multiply(x2));
 }
开发者ID:ubberkid,项目名称:PeerATT,代码行数:4,代码来源:ECFieldElement.cs

示例5: LucasSequence

        private BigInteger[] LucasSequence(
            BigInteger	P,
            BigInteger	Q,
            BigInteger	k)
        {
            // TODO Research and apply "common-multiplicand multiplication here"

            int n = k.BitLength;
            int s = k.GetLowestSetBit();

            Debug.Assert(k.TestBit(s));

            BigInteger Uh = BigInteger.One;
            BigInteger Vl = BigInteger.Two;
            BigInteger Vh = P;
            BigInteger Ql = BigInteger.One;
            BigInteger Qh = BigInteger.One;

            for (int j = n - 1; j >= s + 1; --j)
            {
                Ql = ModMult(Ql, Qh);

                if (k.TestBit(j))
                {
                    Qh = ModMult(Ql, Q);
                    Uh = ModMult(Uh, Vh);
                    Vl = ModReduce(Vh.Multiply(Vl).Subtract(P.Multiply(Ql)));
                    Vh = ModReduce(Vh.Multiply(Vh).Subtract(Qh.ShiftLeft(1)));
                }
                else
                {
                    Qh = Ql;
                    Uh = ModReduce(Uh.Multiply(Vl).Subtract(Ql));
                    Vh = ModReduce(Vh.Multiply(Vl).Subtract(P.Multiply(Ql)));
                    Vl = ModReduce(Vl.Multiply(Vl).Subtract(Ql.ShiftLeft(1)));
                }
            }

            Ql = ModMult(Ql, Qh);
            Qh = ModMult(Ql, Q);
            Uh = ModReduce(Uh.Multiply(Vl).Subtract(Ql));
            Vl = ModReduce(Vh.Multiply(Vl).Subtract(P.Multiply(Ql)));
            Ql = ModMult(Ql, Qh);

            for (int j = 1; j <= s; ++j)
            {
                Uh = ModMult(Uh, Vl);
                Vl = ModReduce(Vl.Multiply(Vl).Subtract(Ql.ShiftLeft(1)));
                Ql = ModMult(Ql, Ql);
            }

            return new BigInteger[] { Uh, Vl };
        }
开发者ID:ubberkid,项目名称:PeerATT,代码行数:53,代码来源:ECFieldElement.cs

示例6: TestDivRanges

 private void TestDivRanges(BigInteger i)
 {
     BigInteger bound = i.Multiply(two);
     for (BigInteger j = bound.Negate(); j.CompareTo(bound) <= 0; j = j
             .Add(i)) {
         BigInteger innerbound = j.Add(two);
         BigInteger k = j.Subtract(two);
         for (; k.CompareTo(innerbound) <= 0; k = k.Add(one)) {
             TestDiv(k, i);
         }
     }
 }
开发者ID:deveel,项目名称:deveel-math,代码行数:12,代码来源:BigIntegerTest.cs

示例7: ProcessBlock

		/**
		* Process a single block using the basic ElGamal algorithm.
		*
		* @param in the input array.
		* @param inOff the offset into the input buffer where the data starts.
		* @param length the length of the data to be processed.
		* @return the result of the ElGamal process.
		* @exception DataLengthException the input block is too large.
		*/
		public byte[] ProcessBlock(
			byte[]	input,
			int		inOff,
			int		length)
		{
			if (key == null)
				throw new InvalidOperationException("ElGamal engine not initialised");

			int maxLength = forEncryption
				?	(bitSize - 1 + 7) / 8
				:	GetInputBlockSize();

			if (length > maxLength)
				throw new DataLengthException("input too large for ElGamal cipher.\n");

			BigInteger p = key.Parameters.P;

			byte[] output;
			if (key is ElGamalPrivateKeyParameters) // decryption
			{
				int halfLength = length / 2;
				BigInteger gamma = new BigInteger(1, input, inOff, halfLength);
				BigInteger phi = new BigInteger(1, input, inOff + halfLength, halfLength);

				ElGamalPrivateKeyParameters priv = (ElGamalPrivateKeyParameters) key;

				// a shortcut, which generally relies on p being prime amongst other things.
				// if a problem with this shows up, check the p and g values!
				BigInteger m = gamma.ModPow(p.Subtract(BigInteger.One).Subtract(priv.X), p).Multiply(phi).Mod(p);

				output = m.ToByteArrayUnsigned();
			}
			else // encryption
			{
				BigInteger tmp = new BigInteger(1, input, inOff, length);

				if (tmp.BitLength >= p.BitLength)
					throw new DataLengthException("input too large for ElGamal cipher.\n");


				ElGamalPublicKeyParameters pub = (ElGamalPublicKeyParameters) key;

				BigInteger pSub2 = p.Subtract(BigInteger.Two);

				// TODO In theory, a series of 'k', 'g.ModPow(k, p)' and 'y.ModPow(k, p)' can be pre-calculated
				BigInteger k;
				do
				{
					k = new BigInteger(p.BitLength, random);
				}
				while (k.Sign == 0 || k.CompareTo(pSub2) > 0);

				BigInteger g = key.Parameters.G;
				BigInteger gamma = g.ModPow(k, p);
				BigInteger phi = tmp.Multiply(pub.Y.ModPow(k, p)).Mod(p);

				output = new byte[this.GetOutputBlockSize()];

				// TODO Add methods to allow writing BigInteger to existing byte array?
				byte[] out1 = gamma.ToByteArrayUnsigned();
				byte[] out2 = phi.ToByteArrayUnsigned();
				out1.CopyTo(output, output.Length / 2 - out1.Length);
				out2.CopyTo(output, output.Length - out2.Length);
			}

			return output;
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:76,代码来源:ElGamalEngine.cs

示例8: TestModInverse

        public void TestModInverse()
        {
            for (int i = 0; i < 10; ++i)
            {
                BigInteger p = BigInteger.ProbablePrime(64, Rnd);
                BigInteger q = new BigInteger(63, Rnd).Add(One);
                BigInteger inv = q.ModInverse(p);
                BigInteger inv2 = inv.ModInverse(p);

                Assert.AreEqual(q, inv2);
                Assert.AreEqual(One, q.Multiply(inv).Mod(p));
            }
        }
开发者ID:ChemicalRocketeer,项目名称:BigMath,代码行数:13,代码来源:BigIntegerTest.cs

示例9: TestGcd

        public void TestGcd()
        {
            for (int i = 0; i < 10; ++i)
            {
                BigInteger fac = new BigInteger(32, Rnd).Add(Two);
                BigInteger p1 = BigInteger.ProbablePrime(63, Rnd);
                BigInteger p2 = BigInteger.ProbablePrime(64, Rnd);

                BigInteger gcd = fac.Multiply(p1).Gcd(fac.Multiply(p2));

                Assert.AreEqual(fac, gcd);
            }
        }
开发者ID:ChemicalRocketeer,项目名称:BigMath,代码行数:13,代码来源:BigIntegerTest.cs

示例10: TestDivide

        public void TestDivide()
        {
            for (int i = -5; i <= 5; ++i)
            {
                try
                {
                    Val(i).Divide(Zero);
                    Assert.Fail("expected ArithmeticException");
                }
                catch (ArithmeticException)
                {
                }
            }

            const int product = 1*2*3*4*5*6*7*8*9;
            const int productPlus = product + 1;

            BigInteger bigProduct = Val(product);
            BigInteger bigProductPlus = Val(productPlus);

            for (int divisor = 1; divisor < 10; ++divisor)
            {
                // Exact division
                BigInteger expected = Val(product/divisor);

                Assert.AreEqual(expected, bigProduct.Divide(Val(divisor)));
                Assert.AreEqual(expected.Negate(), bigProduct.Negate().Divide(Val(divisor)));
                Assert.AreEqual(expected.Negate(), bigProduct.Divide(Val(divisor).Negate()));
                Assert.AreEqual(expected, bigProduct.Negate().Divide(Val(divisor).Negate()));

                expected = Val((product + 1)/divisor);

                Assert.AreEqual(expected, bigProductPlus.Divide(Val(divisor)));
                Assert.AreEqual(expected.Negate(), bigProductPlus.Negate().Divide(Val(divisor)));
                Assert.AreEqual(expected.Negate(), bigProductPlus.Divide(Val(divisor).Negate()));
                Assert.AreEqual(expected, bigProductPlus.Negate().Divide(Val(divisor).Negate()));
            }

            for (int rep = 0; rep < 10; ++rep)
            {
                var a = new BigInteger(100 - rep, 0, Rnd);
                var b = new BigInteger(100 + rep, 0, Rnd);
                var c = new BigInteger(10 + rep, 0, Rnd);
                BigInteger d = a.Multiply(b).Add(c);
                BigInteger e = d.Divide(a);

                Assert.AreEqual(b, e);
            }

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

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

                Assert.AreEqual(bShift, b.Divide(a), data);
                Assert.AreEqual(bShift.Negate(), b.Divide(a.Negate()), data);
                Assert.AreEqual(bShift.Negate(), b.Negate().Divide(a), data);
                Assert.AreEqual(bShift, b.Negate().Divide(a.Negate()), data);
            }

            // Regression
            {
                int shift = 63;
                BigInteger a = One.ShiftLeft(shift);
                var b = new BigInteger(1, "2504b470dc188499".HexToBytes());
                BigInteger bShift = b.ShiftRight(shift);

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

                Assert.AreEqual(bShift, b.Divide(a), data);
                Assert.AreEqual(bShift.Negate(), b.Divide(a.Negate()), data);
                //				Assert.AreEqual(bShift.Negate(), b.Negate().Divide(a), data);
                Assert.AreEqual(bShift, b.Negate().Divide(a.Negate()), data);
            }
        }
开发者ID:ChemicalRocketeer,项目名称:BigMath,代码行数:80,代码来源:BigIntegerTest.cs

示例11: Mult_pos_neg_is_neg

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

示例12: Mult_3

 public void Mult_3()
 {
     BigInteger x = new BigInteger(1, new uint[] { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF });
     BigInteger y = new BigInteger(1, new uint[] { 0x1, 0x1});
     BigInteger z = x.Multiply(y);
     Expect(SameValue(z, 1, new uint[] { 0x1, 0x0, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF }));
 }
开发者ID:richhickey,项目名称:clojure-clr,代码行数:7,代码来源:BigIntegerTests.cs

示例13: Mult_2

 public void Mult_2()
 {
     BigInteger x = new BigInteger(1, new uint[] { 0xFFFFFFFF, 0xF0000000 });
     BigInteger y = new BigInteger(1, new uint[] { 0x2 });
     BigInteger z = x.Multiply(y);
     Expect(SameValue(z, 1, new uint[] { 0x1, 0xFFFFFFFF, 0xE0000000 }));
 }
开发者ID:richhickey,项目名称:clojure-clr,代码行数:7,代码来源:BigIntegerTests.cs

示例14: Mult_1

 public void Mult_1()
 {
     BigInteger x = new BigInteger(1, new uint[] { 100 });
     BigInteger y = new BigInteger(1, new uint[] { 200 });
     BigInteger z = x.Multiply(y);
     Expect(SameValue(z, 1, new uint[] { 20000 }));
 }
开发者ID:richhickey,项目名称:clojure-clr,代码行数:7,代码来源:BigIntegerTests.cs

示例15: ApproximateDivisionByN

		/**
		* Approximate division by <code>n</code>. For an integer
		* <code>k</code>, the value <code>&#955; = s k / n</code> is
		* computed to <code>c</code> bits of accuracy.
		* @param k The parameter <code>k</code>.
		* @param s The curve parameter <code>s<sub>0</sub></code> or
		* <code>s<sub>1</sub></code>.
		* @param vm The Lucas Sequence element <code>V<sub>m</sub></code>.
		* @param a The parameter <code>a</code> of the elliptic curve.
		* @param m The bit length of the finite field
		* <code><b>F</b><sub>m</sub></code>.
		* @param c The number of bits of accuracy, i.e. the scale of the returned
		* <code>SimpleBigDecimal</code>.
		* @return The value <code>&#955; = s k / n</code> computed to
		* <code>c</code> bits of accuracy.
		*/
		public static SimpleBigDecimal ApproximateDivisionByN(BigInteger k,
			BigInteger s, BigInteger vm, sbyte a, int m, int c)
		{
			int _k = (m + 5)/2 + c;
			BigInteger ns = k.ShiftRight(m - _k - 2 + a);

			BigInteger gs = s.Multiply(ns);

			BigInteger hs = gs.ShiftRight(m);

			BigInteger js = vm.Multiply(hs);

			BigInteger gsPlusJs = gs.Add(js);
			BigInteger ls = gsPlusJs.ShiftRight(_k-c);
			if (gsPlusJs.TestBit(_k-c-1))
			{
				// round up
				ls = ls.Add(BigInteger.One);
			}

			return new SimpleBigDecimal(ls, c);
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:38,代码来源:Tnaf.cs


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