本文整理汇总了C#中Lidgren.Network.NetBigInteger.Add方法的典型用法代码示例。如果您正苦于以下问题:C# NetBigInteger.Add方法的具体用法?C# NetBigInteger.Add怎么用?C# NetBigInteger.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBigInteger
的用法示例。
在下文中一共展示了NetBigInteger.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: And
public NetBigInteger And(
NetBigInteger value)
{
if (m_sign == 0 || value.m_sign == 0)
{
return Zero;
}
int[] aMag = m_sign > 0
? m_magnitude
: Add(One).m_magnitude;
int[] bMag = value.m_sign > 0
? value.m_magnitude
: value.Add(One).m_magnitude;
bool resultNeg = m_sign < 0 && value.m_sign < 0;
int resultLength = System.Math.Max(aMag.Length, bMag.Length);
int[] resultMag = new int[resultLength];
int aStart = resultMag.Length - aMag.Length;
int bStart = resultMag.Length - bMag.Length;
for (int i = 0; i < resultMag.Length; ++i)
{
int aWord = i >= aStart ? aMag[i - aStart] : 0;
int bWord = i >= bStart ? bMag[i - bStart] : 0;
if (m_sign < 0)
{
aWord = ~aWord;
}
if (value.m_sign < 0)
{
bWord = ~bWord;
}
resultMag[i] = aWord & bWord;
if (resultNeg)
{
resultMag[i] = ~resultMag[i];
}
}
NetBigInteger result = new NetBigInteger(1, resultMag, true);
if (resultNeg)
{
result = result.Not();
}
return result;
}
示例2: ComputeClientSessionValue
/// <summary>
/// Computes the client session value
/// </summary>
public static byte[] ComputeClientSessionValue(byte[] serverPublicEphemeral, byte[] xdata, byte[] udata, byte[] clientPrivateEphemeral)
{
// (B - kg^x) ^ (a + ux) (mod N)
var B = new NetBigInteger(NetUtility.ToHexString(serverPublicEphemeral), 16);
var x = new NetBigInteger(NetUtility.ToHexString(xdata), 16);
var u = new NetBigInteger(NetUtility.ToHexString(udata), 16);
var a = new NetBigInteger(NetUtility.ToHexString(clientPrivateEphemeral), 16);
var bx = g.ModPow(x, N);
var btmp = B.Add(N.Multiply(k)).Subtract(bx.Multiply(k)).Mod(N);
return btmp.ModPow(x.Multiply(u).Add(a), N).ToByteArrayUnsigned();
}