本文整理汇总了C#中System.Numerics.BigInteger.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.Equals方法的具体用法?C# BigInteger.Equals怎么用?C# BigInteger.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.Equals方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: facto
static BigInteger facto(BigInteger num)
{
if (num < 0)
return 0;
else if (num.Equals(0))
return 1;
else
return num * facto(num - 1);
}
示例2: Multiply
public Point Multiply(Point p, BigInteger x)
{
if (x.Equals(BigInteger.Zero)) return p.Curve.Infinity;
if ((x % 2).Equals(BigInteger.One))
{
return p + Multiply(p, x - 1);
}
return Multiply(p + p, x / 2);
}
示例3: FindBySerialNumber
public void FindBySerialNumber(BigInteger hexValue, BigInteger decimalValue)
{
FindCore(
cert =>
{
byte[] serialBytes = cert.GetSerialNumber();
BigInteger serialNumber = FindPal.PositiveBigIntegerFromByteArray(serialBytes);
bool match = hexValue.Equals(serialNumber) || decimalValue.Equals(serialNumber);
return match;
});
}
示例4: ExpMod
private static BigInteger ExpMod(BigInteger number, BigInteger exponent, BigInteger modulo)
{
if (exponent.Equals(BigInteger.Zero))
{
return BigInteger.One;
}
BigInteger t = BigInteger.Pow(ExpMod(number, exponent / Two, modulo), 2).Mod(modulo);
if (!exponent.IsEven)
{
t *= number;
t = t.Mod(modulo);
}
return t;
}
示例5: ScalarMul
private static Tuple<BigInteger, BigInteger> ScalarMul(Tuple<BigInteger, BigInteger> p, BigInteger e)
{
if (e.Equals(BigInteger.Zero))
{
return new Tuple<BigInteger, BigInteger>(BigInteger.Zero, BigInteger.One);
}
var q = ScalarMul(p, e / Two);
q = EdwardsSquare(q.Item1, q.Item2);
if (!e.IsEven) q = Edwards(q.Item1, q.Item2, p.Item1, p.Item2);
return q;
}
示例6: DefaultCtorWorks
public void DefaultCtorWorks ()
{
var a = new BigInteger ();
Assert.AreEqual (BigInteger.One, ++a, "#1");
a = new BigInteger ();
Assert.AreEqual (BigInteger.MinusOne, --a, "#2");
a = new BigInteger ();
Assert.AreEqual (BigInteger.MinusOne, ~a, "#3");
a = new BigInteger ();
Assert.AreEqual ("0", a.ToString (), "#4");
a = new BigInteger ();
Assert.AreEqual (true, a == a, "#5");
a = new BigInteger ();
Assert.AreEqual (false, a < a, "#6");
a = new BigInteger ();
Assert.AreEqual (true, a < 10l, "#7");
a = new BigInteger ();
Assert.AreEqual (true, a.IsEven, "#8");
a = new BigInteger ();
Assert.AreEqual (0, (int)a, "#9");
a = new BigInteger ();
Assert.AreEqual (0, (uint)a, "#10");
a = new BigInteger ();
Assert.AreEqual (0, (ulong)a, "#11");
a = new BigInteger ();
Assert.AreEqual (true, a.Equals (a), "#12");
a = new BigInteger ();
Assert.AreEqual (a, BigInteger.Min (a, a), "#13");
a = new BigInteger ();
Assert.AreEqual (a, BigInteger.GreatestCommonDivisor (a, a), "#14");
a = new BigInteger ();
Assert.AreEqual (BigInteger.Zero.GetHashCode (), a.GetHashCode (), "#15");
}
示例7: ReKeyBuddyKeys
private void ReKeyBuddyKeys(UInt32 buddy_key_id, BigInteger buddy_public_key)
{
/*is it the same public key we know? */
if (buddy_public_key.Equals(_my_buddy_recent_dh_public_key))
return;
_my_buddy_old_dh_public_key = _my_buddy_recent_dh_public_key;
_my_buddy_recent_dh_public_key = buddy_public_key;
_my_buddy_old_dh_public_key_id = _my_buddy_recent_dh_public_key_id;
_my_buddy_recent_dh_public_key_id++;
}
示例8: VerifyServerProof
/// <summary>
/// Verifies that the server's proof value matches the value
/// calculated by the client.
/// </summary>
/// <param name="serverProof">The 20-byte server proof.</param>
/// <exception cref="ArgumentOutOfRangeException">Thrown if
/// the server proof value is not exactly 20 bytes.</exception>
/// <exception cref="InvalidOperationException">Thrown if the object has not
/// yet been initialized.</exception>
/// <remarks>
/// This method should be called after the <see cref="LoginProof(byte[], int, int, byte[], byte[])">LoginProof</see> method.
/// </remarks>
/// <returns><b>True</b> if the server proof is valid;
/// otherwise <b>false</b>.</returns>
public bool VerifyServerProof(byte[] serverProof)
{
if (serverProof.Length != 20)
throw new ArgumentOutOfRangeException("Server proof must be exactly 20 bytes.");
using (MemoryStream ms_m2 = new MemoryStream(92))
{
BinaryWriter bw = new BinaryWriter(ms_m2);
bw.Write(EnsureArrayLength(A.ToByteArray(), 32));
bw.Write(m1.ToByteArray());
bw.Write(k);
byte[] client_m2_data = ms_m2.GetBuffer();
ms_m2.Close();
byte[] client_hash_m2 = s_sha.ComputeHash(client_m2_data);
BigInteger client_m2 = new BigInteger(client_hash_m2);
BigInteger server_m2 = new BigInteger(serverProof);
Debug.WriteLine(client_m2.ToHexString(), "Client");
Debug.WriteLine(server_m2.ToHexString(), "Server");
return client_m2.Equals(server_m2);
}
}
示例9: ValidateServerSignature
/// <summary>
/// Validates a Warcraft III server signature.
/// </summary>
/// <param name="serverSignature">The server signature from
/// Battle.net's SID_AUTH_INFO message.</param>
/// <param name="ipAddress">The IPv4 address of the server
/// currently connected-to.</param>
/// <returns><b>True</b> if the signature matches;
/// otherwise <b>false</b>.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if
/// the server signature is not exactly 128 bytes.</exception>
public static bool ValidateServerSignature(byte[] serverSignature,
byte[] ipAddress)
{
// code based on iago's code.
if (serverSignature.Length != 128)
throw new ArgumentOutOfRangeException("The server signature must be exactly 128 bytes long.");
BigInteger key = new BigInteger(new byte[] { 0, 1, 0, 1 } /* ReverseArray(new BigInteger((ulong)SignatureKey).GetBytes()) */);
BigInteger mod = BigInteger.Parse(ServerModulus, NumberStyles.HexNumber);
BigInteger sig = new BigInteger(ReverseArray(serverSignature));
byte[] result = BigInteger.ModPow(sig, key, mod).ToByteArray();
BigInteger res = new BigInteger(ReverseArray(result));
using (MemoryStream ms_res = new MemoryStream(result.Length))
{
ms_res.Write(ipAddress, 0, 4);
for (int i = 4; i < result.Length; i++)
ms_res.WriteByte(0xbb);
ms_res.Seek(-1, SeekOrigin.Current);
ms_res.WriteByte(0x0b);
BigInteger cor_res = new BigInteger(ms_res.GetBuffer());
return cor_res.Equals(res);
}
}
示例10: FindBySerialNumber
public unsafe void FindBySerialNumber(BigInteger hexValue, BigInteger decimalValue)
{
FindCore(
delegate(SafeCertContextHandle pCertContext)
{
byte[] actual = pCertContext.CertContext->pCertInfo->SerialNumber.ToByteArray();
GC.KeepAlive(pCertContext);
// Convert to BigInteger as the comparison must not fail due to spurious leading zeros
BigInteger actualAsBigInteger = PositiveBigIntegerFromByteArray(actual);
return hexValue.Equals(actualAsBigInteger) || decimalValue.Equals(actualAsBigInteger);
});
}