java - Elliptic Curve Multiplication -


i having trouble getting correct results when performing multiplication of elliptic curve points. have been able addition working when trying multiply point confused on proper way add previous values. doing without javas ec points.

example: expected: 12(2,7)=(153,36) results: 12(2,7)=(55,121)

private static int = 11; private static int mod = 167;  public static void main(string[] args) {      int[] p1 = { 2, 7 };     int[] p2 = addpoints(new int[] { 1, 4 }, new int[] { 3, 1 });     system.out.println("adding: (" + p2[0] + "," + p2[1] + ")");      int[] p3 = multiplypoint(12, p1);      system.out.println("multiplying: (" + p3[0] + "," + p3[1] + ")");  }  public static int[] multiplypoint(int iterations, int[] point) {     int[] newpoint = new int[2];      (int = 1; < iterations; i++) {          system.out.println("(" + newpoint[0] + "," + newpoint[1] + ")");         newpoint = addpoints(newpoint, point);     }      return newpoint; }  public static int[] addpoints(int[] p1, int[] p2) {     int[] p3 = { 0, 0 };      int m;     if (p1[0] == p2[0] && p1[1] == p2[1])         m = mod(((3 * p1[0] * p1[0]) + a) / (2 * p1[1]), mod);     else         m = mod((int) p2[1] - p1[1], mod) / mod(p2[0] - p1[0], mod);      p3[0] = mod((int) (math.pow(m, 2) - p1[0] - p2[0]), mod);     p3[1] = mod((m * (p1[0] - p3[0]) - p1[1]), mod);      return p3; }  /**  * used because java's default modulus operator not give correct  * value negative numbers  *   * @param value  *            number perform mod operation on  * @param divisor  *            mod  * @return modulus of number mod divisor... should work  *         number  */ public static int mod(int value, int divisor) {     return ((value % divisor + divisor) % divisor); } 

thanks

edit: still unsuccessful

public static int[] multiplypoint(int iterations, int[] point) {     int[] newpoint = new int[2];     string binary = integer.tobinarystring(iterations);     system.out.println(binary);      (int = 0; < binary.length(); i++) {          system.out.println("(" + newpoint[0] + "," + newpoint[1] + ")");          if (binary.charat(i) == '1')             newpoint = addpoints(newpoint, point);         point = doublepoint(point);      }      return newpoint; }  public static int[] doublepoint(int[] point) {     int[] newpoint = new int[2];      int m = mod(((3 * point[0] * point[0]) + a) / (2 * point[1]), mod);     newpoint[0] = mod((int) (math.pow(m, 2) - point[0] - point[0]), mod);     newpoint[1] = mod((m * (point[0] - newpoint[0]) - point[1]), mod);      return newpoint; }  public static int[] addpoints(int[] p1, int[] p2) {     int[] p3 = new int[2];      int m = mod((int) p2[1] - p1[1], mod) / mod(p2[0] - p1[0], mod);      p3[0] = mod((int) (math.pow(m, 2) - p1[0] - p2[0]), mod);     p3[1] = mod((m * (p1[0] - p3[0]) - p1[1]), mod);      return p3; } 


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -