本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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();
}
示例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));
}
示例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");
}
示例7: modInverse
private static BigInteger modInverse(BigInteger a, BigInteger mod)
{
return a.modInverse(mod);
}
示例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;
}