當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。