2016-12-22 6 views
0

Ich arbeite an einem kleinen persönlichen Projekt mit elliptischen Kurven, und ich habe ein bisschen Schwierigkeiten mit der Instanz Variablen der Kurve. Die Variablen werden in der main-Methode korrekt gedruckt, aber die Druckmethode gibt immer zurück, dass jede Variable gleich 0 ist. Sieht jemand eine Möglichkeit, dies zu beheben? Bitte tragen Sie mit mir, ich weiß, dass dies ein ziemlich triviales Problem ist.Einfache Instanz Variable Problem

public class ellipticcurve { 

public int A, B, p; 
public ellipticcurve(int A, int B, int p) { 
    A = this.A; 
    B = this.B; 
    p = this.p; 
    // E:= Y^2 = X^3 + AX + B 
} 

public static boolean isAllowed(int a, int b, int p) { 
    return ((4*(Math.pow(a, 3)) + 27*(Math.pow(b, 2)))%p != 0); 
} 

public static void printCurve(ellipticcurve E) { 
    System.out.println("E(F" + E.p + ") := Y^2 = X^3 + " + E.A + "X + " + E.B + "."); 
} 

public static void main(String[] args) { 
    ArgsProcessor ap = new ArgsProcessor(args); 
    int a = ap.nextInt("A-value:"); 
    int b = ap.nextInt("B-value:"); 
    int p = ap.nextInt("Prime number p for the field Fp over which the curve is defined:"); 

    while (isAllowed(a, b, p) == false) { 
     System.out.println("The parameters you have entered do not satisfy the " 
       + "congruence 4A^3 + 27B^2 != 0 modulo p."); 
     a = ap.nextInt("Choose a new A-value:"); 
     b = ap.nextInt("Choose a new B-value:"); 
     p = ap.nextInt("Choose a new prime number p for the field Fp over which the curve is defined:"); 
    } 

    ellipticcurve curve = new ellipticcurve(a, b, p); 
    System.out.println(curve.A + " " + curve.B + " " + curve.p); 
    printCurve(curve); 
    System.out.println("The elliptic curve is given by E(F" + p 
      + ") := Y^2 = X^3 + " + a + "X + " + b + "."); 
} 

Antwort

2

In Ihrem Konstruktor sollte es auf diese Weise sein.

public ellipticcurve(int A, int B, int p) { 
    this.A = A; 
    this.B = B; 
    this.p = p; 
    // E:= Y^2 = X^3 + AX + B 
} 

statt

public ellipticcurve(int A, int B, int p) { 
    A = this.A; 
    B = this.B; 
    p = this.p; 
    // E:= Y^2 = X^3 + AX + B 
} 

Sie die Instanz-Variable in den Konstruktor übergeben an die Variable zuweisen, so wird die Instanz-Variable auf ihren Standardwert initialisiert werden

+0

Das tat es, danke! So ein kleiner Fehler – wucse19