2016-12-22 6 views
0

私は、楕円曲線を含む小さな個人的なプロジェクトに取り組んでいます。私は曲線のインスタンス変数に少し問題があります。変数はmainメソッドで正しく出力されますが、printメソッドは常に各変数が0に等しいことを返します。誰かがこれを修正する方法を見ていますか?私と一緒に抱きしめてください。私はこれがかなり些細な問題であることを知っています。単純なインスタンス変数の問題

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 + "."); 
} 

答えて

2

コンストラクタでは、このようにする必要があります。

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

代わりの

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

インスタンス変数はそれをやった彼らのデフォルト値

+0

に初期化されますので、あなたは、コンストラクタに渡された変数にインスタンス変数を割り当てている、ありがとう!このような小さな間違い – wucse19