public static Ed25519GroupElement toRepresentation(final Ed25519GroupElement g,final CoordinateSystem newCoordinateSystem){
  final BigInteger x;
  final BigInteger y;
  final BigInteger gX=toBigInteger(g.getX().encode());
  final BigInteger gY=toBigInteger(g.getY().encode());
  final BigInteger gZ=toBigInteger(g.getZ().encode());
  final BigInteger gT=null == g.getT() ? null : toBigInteger(g.getT().encode());
switch (g.getCoordinateSystem()) {
case AFFINE:
    x=gX;
  y=gY;
break;
case P2:
case P3:
x=gX.multiply(gZ.modInverse(Ed25519Field.P)).mod(Ed25519Field.P);
y=gY.multiply(gZ.modInverse(Ed25519Field.P)).mod(Ed25519Field.P);
break;
case P1xP1:
x=gX.multiply(gZ.modInverse(Ed25519Field.P)).mod(Ed25519Field.P);
assert gT != null;
y=gY.multiply(gT.modInverse(Ed25519Field.P)).mod(Ed25519Field.P);
break;
case CACHED:
x=gX.subtract(gY).multiply(gZ.multiply(new BigInteger("2")).modInverse(Ed25519Field.P)).mod(Ed25519Field.P);
y=gX.add(gY).multiply(gZ.multiply(new BigInteger("2")).modInverse(Ed25519Field.P)).mod(Ed25519Field.P);
break;
case PRECOMPUTED:
x=gX.subtract(gY).multiply(new BigInteger("2").modInverse(Ed25519Field.P)).mod(Ed25519Field.P);
y=gX.add(gY).multiply(new BigInteger("2").modInverse(Ed25519Field.P)).mod(Ed25519Field.P);
break;
default :
throw new UnsupportedOperationException();
}
switch (newCoordinateSystem) {
case AFFINE:
return Ed25519GroupElement.affine(toFieldElement(x),toFieldElement(y),Ed25519Field.ONE);
case P2:
return Ed25519GroupElement.p2(toFieldElement(x),toFieldElement(y),Ed25519Field.ONE);
case P3:
return Ed25519GroupElement.p3(toFieldElement(x),toFieldElement(y),Ed25519Field.ONE,toFieldElement(x.multiply(y).mod(Ed25519Field.P)));
case P1xP1:
return Ed25519GroupElement.p1xp1(toFieldElement(x),toFieldElement(y),Ed25519Field.ONE,Ed25519Field.ONE);
case CACHED:
return Ed25519GroupElement.cached(toFieldElement(y.add(x).mod(Ed25519Field.P)),toFieldElement(y.subtract(x).mod(Ed25519Field.P)),Ed25519Field.ONE,toFieldElement(D.multiply(new BigInteger("2")).multiply(x).multiply(y).mod(Ed25519Field.P)));
case PRECOMPUTED:
return Ed25519GroupElement.precomputed(toFieldElement(y.add(x).mod(Ed25519Field.P)),toFieldElement(y.subtract(x).mod(Ed25519Field.P)),toFieldElement(D.multiply(new BigInteger("2")).multiply(x).multiply(y).mod(Ed25519Field.P)));
default :
throw new UnsupportedOperationException();
}
}

public static Ed25519GroupElement toRepresentation ( final Ed25519GroupElement g , final CoordinateSystem newCoordinateSystem ) { final BigInteger x ; final BigInteger y ; final BigInteger gX = toBigInteger ( g . getX ( ) . encode ( ) ) ; final BigInteger gY = toBigInteger ( g . getY ( ) . encode ( ) ) ; final BigInteger gZ = toBigInteger ( g . getZ ( ) . encode ( ) ) ; final BigInteger gT = null == g . getT ( ) ? null : toBigInteger ( g . getT ( ) . encode ( ) ) ; switch ( g . getCoordinateSystem ( ) ) { case AFFINE : x = gX ; y = gY ; break ; case P2 : case P3 : x = gX . multiply ( gZ . modInverse ( Ed25519Field . P ) ) . mod ( Ed25519Field . P ) ; y = gY . multiply ( gZ . modInverse ( Ed25519Field . P ) ) . mod ( Ed25519Field . P ) ; break ; case P1xP1 : x = gX . multiply ( gZ . modInverse ( Ed25519Field . P ) ) . mod ( Ed25519Field . P ) ; assert gT != null ; y = gY . multiply ( gT . modInverse ( Ed25519Field . P ) ) . mod ( Ed25519Field . P ) ; break ; case CACHED : x = gX . subtract ( gY ) . multiply ( gZ . multiply ( new BigInteger ( "2" ) ) . modInverse ( Ed25519Field . P ) ) . mod ( Ed25519Field . P ) ; y = gX . add ( gY ) . multiply ( gZ . multiply ( new BigInteger ( "2" ) ) . modInverse ( Ed25519Field . P ) ) . mod ( Ed25519Field . P ) ; break ; case PRECOMPUTED : x = gX . subtract ( gY ) . multiply ( new BigInteger ( "2" ) . modInverse ( Ed25519Field . P ) ) . mod ( Ed25519Field . P ) ; y = gX . add ( gY ) . multiply ( new BigInteger ( "2" ) . modInverse ( Ed25519Field . P ) ) . mod ( Ed25519Field . P ) ; break ; default : throw new UnsupportedOperationException ( ) ; } switch ( newCoordinateSystem ) { case AFFINE : return Ed25519GroupElement . affine ( toFieldElement ( x ) , toFieldElement ( y ) , Ed25519Field . ONE ) ; case P2 : return Ed25519GroupElement . p2 ( toFieldElement ( x ) , toFieldElement ( y ) , Ed25519Field . ONE ) ; case P3 : return Ed25519GroupElement . p3 ( toFieldElement ( x ) , toFieldElement ( y ) , Ed25519Field . ONE , toFieldElement ( x . multiply ( y ) . mod ( Ed25519Field . P ) ) ) ; case P1xP1 : return Ed25519GroupElement . p1xp1 ( toFieldElement ( x ) , toFieldElement ( y ) , Ed25519Field . ONE , Ed25519Field . ONE ) ; case CACHED : return Ed25519GroupElement . cached ( toFieldElement ( y . add ( x ) . mod ( Ed25519Field . P ) ) , toFieldElement ( y . subtract ( x ) . mod ( Ed25519Field . P ) ) , Ed25519Field . ONE , toFieldElement ( D . multiply ( new BigInteger ( "2" ) ) . multiply ( x ) . multiply ( y ) . mod ( Ed25519Field . P ) ) ) ; case PRECOMPUTED : return Ed25519GroupElement . precomputed ( toFieldElement ( y . add ( x ) . mod ( Ed25519Field . P ) ) , toFieldElement ( y . subtract ( x ) . mod ( Ed25519Field . P ) ) , toFieldElement ( D . multiply ( new BigInteger ( "2" ) ) . multiply ( x ) . multiply ( y ) . mod ( Ed25519Field . P ) ) ) ; default : throw new UnsupportedOperationException ( ) ; } }
converts a group element from one coordinate system to another . this method is a helper used to test various methods in ed25519groupelement .
