package x3_1;
import java.math.BigInteger;
import java.security.spec.ECPoint;
public class Pairing {
static BigInteger px = new BigInteger("1");
static BigInteger py = new BigInteger("2");
static BigInteger qx = new BigInteger("8");
static BigInteger qy = new BigInteger("23");
static BigInteger r = new BigInteger("2");
static Integer k = new Integer("1");
static final BigInteger p = new BigInteger(
"1461501637330902918203684832716283019655932542983");
static BigInteger A = new BigInteger("2");
static BigInteger B = new BigInteger("1");
public static void main(String[] args) {
ECPoint P = new ECPoint(px, py);
ECPoint Q = new ECPoint(qx, qy);
ECPoint P2 = Elictip_Adder.ECpointAdder(A, B, p, P, P);
ECPoint Q2 = Elictip_Adder.ECpointAdder(A, B, p, Q, Q);
System.out.println("P = P(" + P.getAffineX() + "," + P.getAffineY() + ")");
System.out.println("Q = Q(" + Q.getAffineX() + "," + Q.getAffineY() + ")");
System.out.println();
BigInteger e1 = Miller_Algorithm.Miller(P2, Q, r, k, A, B, p);
System.out.println("pairing for the two point 2P,Q");
System.out.println("2P = P(" + P2.getAffineX() + "," + P2.getAffineY() + ") online:" + online(P2, A, B, p));
System.out.println("e(2P,Q) = " + e1);
System.out.println();
BigInteger e2 = Miller_Algorithm.Miller(P, Q2, r, k, A, B, p);
System.out.println("pairing for the two point P,2Q");
System.out.println("2Q = Q(" + Q2.getAffineX() + "," + Q2.getAffineY() + ") online:" + online(Q2, A, B, p));
System.out.println("e(P,2Q) = " + e2);
}
public static boolean online (ECPoint P, BigInteger A, BigInteger B, BigInteger p){
BigInteger x = P.getAffineX();
BigInteger y = P.getAffineY();
BigInteger tmp1 = (x.pow(3).add(x.multiply(A)).add(B)).mod(p);
BigInteger tmp2 = y.pow(2).mod(p);
return tmp1.equals(tmp2);
}
}