/// <summary> /// Calculates client's S. /// </summary> /// <param name="N"></param> /// <param name="g"></param> /// <param name="B"></param> /// <param name="k"></param> /// <param name="x"></param> /// <param name="a"></param> /// <param name="u"></param> /// <returns></returns> public static NetBigInteger CalcSClient(NetBigInteger N, NetBigInteger g, NetBigInteger B, NetBigInteger k, NetBigInteger x, NetBigInteger a, NetBigInteger u) { // <premaster secret> = (B - (k * g^x)) ^ (a + (u * x)) % N // (B + (N - ((k*g.ModExp(x,N))%N))) - Do it this way. Thanks Valery. NetBigInteger S = (B.Add(N.Subtract((k.Multiply(g.ModPow(x, N))).Mod(N)))).ModPow(a.Add(u.Multiply(x)), N); return(S); }
public NetBigInteger Add( NetBigInteger value) { if (m_sign == 0) return value; if (m_sign != value.m_sign) { if (value.m_sign == 0) return this; if (value.m_sign < 0) return Subtract(value.Negate()); return value.Subtract(Negate()); } return AddToMagnitude(value.m_magnitude); }
/// <summary> /// Calculates client's S. /// </summary> /// <param name="N"></param> /// <param name="g"></param> /// <param name="B"></param> /// <param name="k"></param> /// <param name="x"></param> /// <param name="a"></param> /// <param name="u"></param> /// <returns></returns> public static NetBigInteger CalcSClient(NetBigInteger N, NetBigInteger g, NetBigInteger B, NetBigInteger k, NetBigInteger x, NetBigInteger a, NetBigInteger u) { // <premaster secret> = (B - (k * g^x)) ^ (a + (u * x)) % N // (B + (N - ((k*g.ModExp(x,N))%N))) - Do it this way. Thanks Valery. NetBigInteger S = (B.Add(N.Subtract((k.Multiply(g.ModPow(x, N))).Mod(N)))).ModPow(a.Add(u.Multiply(x)), N); return S; }