private List <PointECC> compute() { List <PointECC> RPs = new List <PointECC>(); PointECC R = new PointECC(); R.x = Gx; R.y = Gy; lsb_points.Items.Add(" G = (" + R.x.ToString() + ", " + R.y.ToString() + ")"); RPs.Add(R); R = PointDouble(R.x, R.y); lsb_points.Items.Add("2G = (" + R.x.ToString() + ", " + R.y.ToString() + ")"); RPs.Add(R); for (int i = 3; ; i++) { R = P_add_Q(R.x, R.y, Gx, Gy); //R.x = int.PositiveInfinity; if (signal) { signal = false; lsb_points.Items.Add(i.ToString() + "G = Infinity"); return(RPs); } lsb_points.Items.Add(i.ToString() + "G = (" + R.x.ToString() + ", " + R.y.ToString() + ")"); RPs.Add(R); } }
private PointECC PointDouble(int x, int y) { int s = 0, s_tu = 0, s_mau = 1; PointECC RP = new PointECC(); s_tu = 3 * x * x + factorA; if (s_tu > module) { s_tu %= module; } s_mau = 2 * y; if (s_mau == 0) { signal = true; return(RP); } if (Math.Abs(s_mau) != 1) { if (s_mau < 0) { s_mau = -module_denominator(Math.Abs(s_mau), module); } else { s_mau = module_denominator(Math.Abs(s_mau), module); } } s = (s_tu * s_mau); if (s > module) { s %= module; } RP.x = (s * s - 2 * x) % module; if (RP.x < 0) { RP.x = module + RP.x; } RP.y = (s * (x - RP.x) - y) % module; if (RP.y < 0) { RP.y = module + RP.y; } return(RP); }
private PointECC P_add_Q(int xp, int yp, int xq, int yq) { int s = 0, s_tu = 0, s_mau = 1; PointECC RP = new PointECC(); s_tu = yp - yq; if (s_tu > module) { s_tu = s_tu % module; } s_mau = xp - xq; if (s_mau == 0) { signal = true; return(RP); } if (Math.Abs(s_mau) != 1) { if (s_mau < 0) { s_mau = -module_denominator(Math.Abs(s_mau), module); } else { s_mau = module_denominator(Math.Abs(s_mau), module); } } s = (s_tu * s_mau); RP.x = (s * s - (xp + xq)) % module; if (RP.x < 0) { RP.x = module + RP.x; } RP.y = (s * (xp - RP.x) - yp) % module; if (RP.y < 0) { RP.y = module + RP.y; } return(RP); }