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

C# Math.BigInteger类代码示例

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

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



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

示例1: DSAPrivateKeySpec

		public DSAPrivateKeySpec (BigInteger x, BigInteger p, BigInteger q, BigInteger g)
		{
			this.x = x;
			this.p = p;
			this.q = q;
			this.g = g;
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:7,代码来源:DSAPrivateKeySpec.cs


示例2: Bitwise_Base

		public Bitwise_Base() 
		{
			N = new BigInteger(n);
			expectedNls = new BigInteger(ExpectedNLeftShift);
			expectedNrs = new BigInteger(ExpectedNRightShift);
			shiftAmount = ShiftAmount;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:BitwiseTest.cs


示例3: ModPow_0_Even

		public void ModPow_0_Even ()
		{
			BigInteger x = new BigInteger (1);
			BigInteger y = new BigInteger (0);
			BigInteger z = x.ModPow (y, 1024);
			Assert.AreEqual ("1", z.ToString (), "1 pow 0 == 1");
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:7,代码来源:BigIntegerTest.cs


示例4: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.String) { return null; }
            var decrypted = (MCrypto)base.ReadJson(reader, objectType, existingValue, serializer);
            var rsa_privk = new BigInteger[4];
            var bytes = decrypted.Value;
            int startindex = 0;
            for (var i = 0; i < 4; i++)
            {
                var l = ((bytes[startindex + 0] * 256 + bytes[startindex + 1] + 7) >> 3) + 2;
                rsa_privk[i] = Converter.MpiToBigInt(bytes, startindex, l);
                startindex += l;
            }

            if (bytes.Length - startindex < 16)
            {
                return new RSAKey
                {
                    P = rsa_privk[0],
                    Q = rsa_privk[1],
                    D = rsa_privk[2],
                    U = rsa_privk[3],
                    N = BigInteger.Multiply(rsa_privk[0], rsa_privk[1])
                };
            }
            else return null;
        }
开发者ID:exaphaser,项目名称:megadesktop,代码行数:27,代码来源:PrivateKeyConverter.cs


示例5: DSAPublicKeySpec

		public DSAPublicKeySpec (BigInteger y, BigInteger p, BigInteger q, BigInteger g)
		{
			this.y = y;
			this.p = p;
			this.q = q;
			this.g = g;
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:7,代码来源:DSAPublicKeySpec.cs


示例6: Main

        static void Main(string[] args)
        {
            Datacenter datacenterController = new Datacenter();

              var i = new BigInteger(8798782624624);
              Console.WriteLine(i);
              Console.ReadLine();
        }
开发者ID:vikewoods,项目名称:MTProto,代码行数:8,代码来源:Program.cs


示例7: BarrettReduction

            public void BarrettReduction(BigInteger x)
            {
                var n = mod;
                uint k = n.length,
                    kPlusOne = k + 1,
                    kMinusOne = k - 1;

                // x < mod, so nothing to do.
                if (x.length < k) return;

                BigInteger q3;

                //
                // Validate pointers
                //
                if (x.data.Length < x.length) throw new IndexOutOfRangeException("x out of range");

                // q1 = x / b^ (k-1)
                // q2 = q1 * constant
                // q3 = q2 / b^ (k+1), Needs to be accessed with an offset of kPlusOne

                // TODO: We should the method in HAC p 604 to do this (14.45)
                q3 = new BigInteger(Sign.Positive, x.length - kMinusOne + constant.length);
                Kernel.Multiply(x.data, kMinusOne, x.length - kMinusOne, constant.data, 0, constant.length, q3.data, 0);

                // r1 = x mod b^ (k+1)
                // i.e. keep the lowest (k+1) words

                var lengthToCopy = x.length > kPlusOne ? kPlusOne : x.length;

                x.length = lengthToCopy;
                x.Normalize();

                // r2 = (q3 * n) mod b^ (k+1)
                // partial multiplication of q3 and n

                var r2 = new BigInteger(Sign.Positive, kPlusOne);
                Kernel.MultiplyMod2p32pmod(q3.data, (int) kPlusOne, (int) q3.length - (int) kPlusOne, n.data, 0,
                    (int) n.length, r2.data, 0, (int) kPlusOne);

                r2.Normalize();

                if (r2 <= x)
                {
                    Kernel.MinusEq(x, r2);
                }
                else
                {
                    var val = new BigInteger(Sign.Positive, kPlusOne + 1);
                    val.data[kPlusOne] = 0x00000001;

                    Kernel.MinusEq(val, r2);
                    Kernel.PlusEq(x, val);
                }

                while (x >= n)
                    Kernel.MinusEq(x, n);
            }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:58,代码来源:BigInteger.cs


示例8: SignedBigInteger

 public SignedBigInteger(long a)
 {
     if (a < 0)
     {
         this.Negative = true;
         a *= -1;
     }
     this.Number = new BigInteger((ulong)a);
 }
开发者ID:samphippen,项目名称:precmaths,代码行数:9,代码来源:SignedBigInteger.cs


示例9: WikipediaSanityChecks

 public void WikipediaSanityChecks()
 {
     // http://en.wikipedia.org/wiki/RSA on 25 May 2009
     var c = new BigInteger(855);
     var d = new BigInteger(2753);
     var n = new BigInteger(3233);
     var m = c.ModPow(d, n);
     Assert.AreEqual("123", m.ToString());           
 }
开发者ID:modulexcite,项目名称:TLS-1.0-Analyzer,代码行数:9,代码来源:BigIntegerTests.cs


示例10: GenerateKeyPair

        private void GenerateKeyPair()
        {
            // p and q values should have a length of half the strength in bits
            int pbitlength = ((KeySize + 1) >> 1);
            int qbitlength = (KeySize - pbitlength);
            const uint uint_e = 17;
            e = uint_e; // fixed

            // generate p, prime and (p-1) relatively prime to e
            for (; ; )
            {
                p = BigInteger.GeneratePseudoPrime(pbitlength);
                if (p % uint_e != 1)
                    break;
            }
            // generate a modulus of the required length
            for (; ; )
            {
                // generate q, prime and (q-1) relatively prime to e,
                // and not equal to p
                for (; ; )
                {
                    q = BigInteger.GeneratePseudoPrime(qbitlength);
                    if ((q % uint_e != 1) && (p != q))
                        break;
                }

                // calculate the modulus
                n = p * q;
                if (n.BitCount() == KeySize)
                    break;

                // if we get here our primes aren't big enough, make the largest
                // of the two p and try again
                if (p < q)
                    p = q;
            }

            BigInteger pSub1 = (p - 1);
            BigInteger qSub1 = (q - 1);
            BigInteger phi = pSub1 * qSub1;

            // calculate the private exponent
            d = e.ModInverse(phi);

            // calculate the CRT factors
            dp = d % pSub1;
            dq = d % qSub1;
            qInv = q.ModInverse(p);

            keypairGenerated = true;
            isCRTpossible = true;

            if (KeyGenerated != null)
                KeyGenerated(this, null);
        }
开发者ID:neo1106,项目名称:l2script,代码行数:56,代码来源:RSA.cs


示例11: ModRing_Base

		public ModRing_Base() 
		{
			A = new BigInteger( a );
			B = new BigInteger( b );
			N = new BigInteger( n );
			abModN = new BigInteger( ExpectedABmodN );
			aPowBmodN = new BigInteger( ExpectedApowBmodN );

			mr = new BigInteger.ModulusRing(N);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:10,代码来源:ModRingTest.cs


示例12: PublicKeyOperation

 /// <summary>
 /// Performs the RSA operation Result = <paramref name="message"/>^<paramref name="exponent"/> (mod <paramref name="modulus"/>).
 /// </summary>
 /// <param name="message">The message to perform the operation on.</param>
 /// <param name="exponent">The exponent value to raise the message by.</param>
 /// <param name="modulus">The modulus to divide the results by.</param>
 /// <returns>The value C, such that C = <paramref name="message"/>^<paramref name="exponent"/> (mod <paramref name="modulus"/>).</returns>
 public static byte[] PublicKeyOperation(byte[] message, byte[] exponent, byte[] modulus)
 {
     var m = new BigInteger(message);
     var e = new BigInteger(exponent);
     var n = new BigInteger(modulus);
     var c = m.ModPow(e, n);
     var resultBytes = c.GetBytes();
     
     return resultBytes;
 }
开发者ID:modulexcite,项目名称:TLS-1.0-Analyzer,代码行数:17,代码来源:RsaUtilities.cs


示例13: DefaultRandom

		public void DefaultRandom () 
		{
			// based on bugzilla entry #68452
			BigInteger bi = new BigInteger ();
			Assert.AreEqual (0, bi.BitCount (), "before randomize");
			bi.Randomize ();
			// Randomize returns a random number of BitCount length
			// so in this case it will ALWAYS return 0
			Assert.AreEqual (0, bi.BitCount (), "after randomize");
			Assert.AreEqual (new BigInteger (0), bi, "Zero");
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:11,代码来源:BigIntegerTest.cs


示例14: Power

        public static BigInteger Power(this BigInteger a, BigInteger b)
        {
            BigInteger value = 1;

              for (BigInteger count = 0; count < b; count += 1)
              {
            value *= a;
              }

              return value;
        }
开发者ID:dbrgn,项目名称:pi-vote,代码行数:11,代码来源:BigIntegerExtensions.cs


示例15: ModulusRing

            public ModulusRing(BigInteger modulus)
            {
                mod = modulus;

                // calculate constant = b^ (2k) / m
                var i = mod.length << 1;

                constant = new BigInteger(Sign.Positive, i + 1);
                constant.data[i] = 0x00000001;

                constant = constant/mod;
            }
开发者ID:claudiuslollarius,项目名称:monotorrent,代码行数:12,代码来源:BigInteger.cs


示例16: ModPow_2

		public void ModPow_2 ()
		{
			// #70169
			BigInteger b = new BigInteger (10);
			BigInteger m = new BigInteger (32);
			// after 40 we start loosing double precision and result will differ
			for (int i=1; i < 40; i++) {
				BigInteger e = new BigInteger (i);
				BigInteger r = e.ModPow (b, m);
				long expected = (long) myalias.Math.Pow (i, 10) % 32;
				Assert.AreEqual (expected.ToString (), r.ToString (), i.ToString ());
			}
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:13,代码来源:BigIntegerTest.cs


示例17: GetE

		//    myKeyAgree=KeyAgreement.getInstance("DiffieHellman");
		/// <exception cref="System.Exception"></exception>
		public virtual byte[] GetE()
		{
			if (e == null)
			{
				DHParameterSpec dhSkipParamSpec = new DHParameterSpec(p, g);
				myKpairGen.Initialize(dhSkipParamSpec);
				Sharpen.KeyPair myKpair = myKpairGen.GenerateKeyPair();
				myKeyAgree.Init(myKpair.GetPrivate());
				//    BigInteger x=((javax.crypto.interfaces.DHPrivateKey)(myKpair.getPrivate())).getX();
				e = ((DHPublicKey)(myKpair.GetPublic())).GetY();
				e_array = e.GetBytes();
			}
			return e_array;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:16,代码来源:DH.cs


示例18: AppliedCryptographySanityChecks

 public void AppliedCryptographySanityChecks()
 {
     // Sanity checks from Applied Cryptography, 2nd Edition p467 - 468
     var p = new BigInteger(47);
     var q = new BigInteger(71);
     var n = p * q;
     var e = new BigInteger(79);
     var d = e.ModInverse((p - 1) * (q - 1));
     Func<int, string> encryptor = m => (new BigInteger(m).ModPow(e, n)).ToString();
     Assert.AreEqual("1570", encryptor(688));
     Assert.AreEqual("2756", encryptor(232));
     Assert.AreEqual("2091", encryptor(687));
     Assert.AreEqual("2276", encryptor(966));
     Assert.AreEqual("2423", encryptor(668));
     Assert.AreEqual("158", encryptor(3));            
 }
开发者ID:modulexcite,项目名称:TLS-1.0-Analyzer,代码行数:16,代码来源:BigIntegerTests.cs


示例19: MakeAESKey

 public void MakeAESKey(string keyExchangeBytes)
 {
     BigInteger A = new BigInteger(keyExchangeBytes);
     byte[] R = A.modPow(privateKey, Module).getBytes();
     aesKey = new byte[16];
     Array.Copy(R, aesKey, 16);
     for (int i = 0; i < 16; i++)
     {
         byte tmp = (byte)(aesKey[i] >> 4);
         byte tmp2 = (byte)(aesKey[i] & 0xF);
         if (tmp > 9)
             tmp = (byte)(tmp - 9);
         if (tmp2 > 9)
             tmp2 = (byte)(tmp2 - 9);
         aesKey[i] = (byte)( tmp << 4 | tmp2);
     }
 }
开发者ID:yasuhiro91,项目名称:SagaECO,代码行数:17,代码来源:Encryption.cs


示例20: Calculate

        public static byte[] Calculate(BigInteger a, BigInteger b)
        {
            byte[] bytes;
            lock (locker)
                bytes = a.ModPow(b, prime).GetBytes();

            if (bytes.Length < 96)
            {
                byte[] oldBytes = bytes;
                bytes = new byte[96];
                Array.Copy(oldBytes, 0, bytes, 96 - oldBytes.Length, oldBytes.Length);
                for (int i = 0; i < (96 - oldBytes.Length); i++)
                    bytes[i] = 0;
            }

            return bytes;
        }
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:17,代码来源:ModuloCalculator.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Security.ASN1类代码示例发布时间:2022-05-26
下一篇:
C# ILASM.CodeGen类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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