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


C# BigInteger.modInverse方法代码示例

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


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

示例1: GetPrivateKeyExponent

        public static string GetPrivateKeyExponent(string p, string q)
        {
            BigInteger e = new BigInteger(Convert.ToInt64(17));
            BigInteger d = e.modInverse((new BigInteger(p, _RADIX) - 1) * (new BigInteger(q, _RADIX) - 1));

            return d.ToString(_RADIX);
        }
开发者ID:persalteas,项目名称:KnightOS,代码行数:7,代码来源:Signature.cs

示例2: ModSqrt

 //функция вычисления квадратоного корня по модулю простого числа q
 public BigInteger ModSqrt(BigInteger a, BigInteger q)
 {
     BigInteger b = new BigInteger();
     do
     {
         b.genRandomBits(255, new Random());
     } while (Legendre(b, q) == 1);
     BigInteger s = 0;
     BigInteger t = q - 1;
     while ((t & 1) != 1)
     {
         s++;
         t = t >> 1;
     }
     BigInteger InvA = a.modInverse(q);
     BigInteger c = b.modPow(t, q);
     BigInteger r = a.modPow(((t + 1) / 2), q);
     BigInteger d = new BigInteger();
     for (int i = 1; i < s; i++)
     {
         BigInteger temp = 2;
         temp = temp.modPow((s - i - 1), q);
         d = (r.modPow(2, q) * InvA).modPow(temp, q);
         if (d == (q - 1))
             r = (r * c) % q;
         c = c.modPow(2, q);
     }
     return r;
 }
开发者ID:msCube,项目名称:Scrambler,代码行数:30,代码来源:DSGost.cs

示例3: RSAKeyPair

 internal RSAKeyPair(BigInteger modulus, BigInteger e, BigInteger d, BigInteger p, BigInteger q)
 {
     _publickey = new RSAPublicKey(e, modulus);
     _d = d;
     _p = p;
     _q = q;
     _u = p.modInverse(q);
 }
开发者ID:satsukitv,项目名称:GranadosRT,代码行数:8,代码来源:RSA.cs

示例4: ReconstructData

    public long ReconstructData(SharedData[] shares)
    {
        BigInteger[] nominators = new BigInteger[numNecessaryParts];

        for (int i = 0; i < numNecessaryParts; i++)
        {
            nominators[i] = 1;

            for (int j = 0; j < numNecessaryParts; j++)
            {
                if (i != j)
                {
                    BigInteger inv = new BigInteger(shares[i].xi) - new BigInteger(shares[j].xi);
                    inv = inv % modP;
                    if (inv < 0)
                    {
                        while (inv <= 0)
                            inv += modP;
                        inv = inv.modInverse(modP);
                    }
                    else if (inv != 1)
                    {
                        inv = inv.modInverse(modP);
                    }

                    nominators[i] = (nominators[i] * (new BigInteger(shares[j].xi) * inv)) % modP;
                }
            }

        }

        for (int i = 0; i < numNecessaryParts; i++)
        {
            nominators[i] = (nominators[i] * new BigInteger(shares[i].yi)) % modP;
        }

        BigInteger nominator = new BigInteger(0);

        for (int i = 0; i < numNecessaryParts; i++)
        {
            nominator = (nominator + nominators[i]) % modP;
        }

        return nominator.LongValue();
    }
开发者ID:mertcetin,项目名称:P2P-Backup,代码行数:45,代码来源:ShamirSS.cs

示例5: rsa

        public rsa()
        {
            Random rn = new Random();

            p = BigInteger.genPseudoPrime(521, 100, rn);
            q = BigInteger.genPseudoPrime(521, 100, rn);
            n = new BigInteger(p * q);

            BigInteger o = new BigInteger((p - 1) * (q - 1));

            int eb=0;
            do
            {
                //eb = rn.Next(2, o.bitCount());
                //e = BigInteger.genPseudoPrime(eb, 100, rn);
                e = new BigInteger(65537);
            }
            while (e > o || e.gcd(o) != new BigInteger(1));

            d = new BigInteger(e.modInverse(o));
        }
开发者ID:Rotariu-Stefan,项目名称:INFO-SI,代码行数:21,代码来源:rsa.cs

示例6: Verify

        public void Verify(byte[] data, byte[] expecteddata)
        {
            byte[] first  = new byte[data.Length/2];
            byte[] second = new byte[data.Length/2];
            Array.Copy(data, 0, first, 0, first.Length);
            Array.Copy(data, first.Length, second, 0, second.Length);
            BigInteger r = new BigInteger(first);
            BigInteger s = new BigInteger(second);

            BigInteger w  = s.modInverse(_q);
            BigInteger u1 = (new BigInteger(expecteddata) * w) % _q;
            BigInteger u2 = (r * w) % _q;
            BigInteger v  = ((_g.modPow(u1, _p) * _y.modPow(u2, _p)) % _p) % _q;
            //Debug.WriteLine(DebugUtil.DumpByteArray(v.GetBytes()));
            //Debug.WriteLine(DebugUtil.DumpByteArray(r.GetBytes()));
            if(v!=r) throw new VerifyException("Failed to verify");
        }
开发者ID:rfyiamcool,项目名称:solrex,代码行数:17,代码来源:DSA.cs

示例7: modInverse

 private static BigInteger modInverse(BigInteger a, BigInteger mod)
 {
     return a.modInverse(mod);
 }
开发者ID:eXcomm,项目名称:otr-1,代码行数:4,代码来源:SM.cs

示例8: genrecshare

        private BigInteger genrecshare(BigInteger Ri, BigInteger x)
        {
            BigInteger inverseX = x.modInverse(q);
            BigInteger Si = new BigInteger(Ri.modPow(inverseX, p)); //to be reviewed
            //Console.WriteLine("\nSi: " + Si);

            return Si;
        }
开发者ID:Rotariu-Stefan,项目名称:INFO-SI,代码行数:8,代码来源:client.cs


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