# Convert affine to projective coordinates and vice versa in ECC?

I am working on a small project. An elliptic curve equation with y^2=x^3-3x+27 mod 43, a point $$Q=(1,38)$$, using point doubling method https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Point_doubling, i got $$2Q(Q+Q)=(41,5)$$. Now in projective coordinate $$Q=(1,38,1)$$ taking $$z=1$$.https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Standard_Projective_Coordinates

Calculating $$2Q$$, I get $$2Q=(22,31,39)$$ and converting to affine coordinate I can't get $$2Q=(41,5)$$.

So, where did I went wrong can anyone explain or am I following the wrong method??

Somewhere you seem to have made a small mistake. $$39$$ is already the inverse of $$Z_{2Q}$$. The correct value of $$Z_{2Q}$$ is $$\mathbf{32}$$.

For the long story, let us first go through the doubling formula one step a time:

if (Y == 0)                     # nope
return POINT_AT_INFINITY
W = a*Z^2 + 3*X^2               # W = 0
S = Y*Z                         # S = 38
B = X*Y*S                       # B = 25
H = W^2 - 8*B                   # H = 15
X' = 2*H*S                      # X'= 22
Y' = W*(4*B - H) - 8*Y^2*S^2    # Y'= 31
Z' = 8*S^3                      # Z'= 32
return (X', Y', Z')


This leaves us with $$2Q = (22 : 31 : \mathbf{32})$$.

To compute the affine representation, we compute $$Z_{2Q}^{-1} = 39$$. Now the affine representation of $$2Q = (XZ^{-1}, YZ^{-1}) = (22 \cdot 39, 31 \cdot 39) = (41, 5)$$.