public static int[] CalculateSum(int[] P, int a, int p) { int lambda = CalculateLambda(P, a, p); int x = GCD.Mod(lambda * lambda - P[0] - P[0], p); int y = GCD.Mod(lambda * (P[0] - x) - P[1], p); return(new int[] { x, y }); }
public static bool VerifyDigitalSign(int[] digitalSign, int[] G, int q, int d, int a, int p) { if (digitalSign[0] <= 1 || digitalSign[1] >= q) { return(false); } int H = points[alphabeth.IndexOf("м"), 0] % 13; // by task int w = GCD.ModInverse(digitalSign[1], q); int u1 = (w * H) % q; int u2 = (w * digitalSign[0]) % q; int[] Q = kP(d, G, a, p), u1G = kP(u1, G, a, p), u2Q = kP(u2, Q, a, p); int v = CalculateSum(u1G, u2Q, p)[0] % q; return(digitalSign[0] == v); }
public static int[] CreateDigitalSign(int[] G, int q, int d, int a, int p) { Console.WriteLine($"G = ({G[0]}, {G[1]}), d = {d}, q = {q}"); int[] digitalSign = new int[2]; int[] kG; int k, t; do { do { k = random.Next(2, q); kG = kP(k, G, a, p); digitalSign[0] = kG[0] % q; } while (digitalSign[0] <= 1); t = GCD.ModInverse(k, q); int H = points[alphabeth.IndexOf("м"), 0] % 13; // by task digitalSign[1] = (t * (H + d * digitalSign[0])) % q; } while (digitalSign[1] <= 0); return(digitalSign); }
private static int CalculateLambda(int[] P, int[] Q, int p) { return(GCD.Mod(GCD.Mod(Q[1] - P[1], p) * GCD.Mod(GCD.ModInverse(Q[0] + GCD.Mod(-P[0], p), p), p), p)); }
private static int CalculateLambda(int[] P, int a, int p) { return(GCD.Mod(GCD.Mod(3 * (P[0] * P[0]) + a, p) * GCD.ModInverse(2 * P[1], p), p)); }