# XZ coordinates for Montgomery curves

I am learning about Elliptic curve and I reached to Montgomery curve with XZ coordinates with this equation: b*y2=x3+a*x2+x and regarding the information from this link: XZ coordinates add and doubling

and I made this small code in matlab to understand the concepts:

% Define the elliptic curve parameters
a = 1;
b = 1;
p = 23;
% Define the base point
X1 = 8;
Y1 = 3;
Z1=1;
%Doubling
X3 = mod((X1^2-Z1^2)^2,p);
Z3 = mod(4*X1*Z1*(X1^2+a*X1*Z1+Z1^2),p);
A = X2+Z2; %X2,Z2 Values?
B = X2-Z2;
C = X3+Z3; %X3,Z3 Does this come from Doubling?
D = X3-Z3;
DA = D*A;
CB = C*B;
X5 = (DA+CB)^2;
Z5 = X1*(DA-CB)^2; %X1 Does this come from Base Point?


in Doubling phase I can Understand X1, Z1 comes from Base Point, but in Addition phase I want to understand the values X2,Z2,X3,Z3,X1 come from where?

Because what I understand that I have base point then from doubling the base point then I got second point so obviously I have base Point X1,Z1 and from doubling I have X3,Z3 what about X2,Z2?

• Any idea about it? Feb 25, 2023 at 12:20
• My trouble in understanding that web page is that I don't know what "differential addition" is. Feb 28, 2023 at 2:11
• @Myria what I understand it is to take -R Value as pseudo value, I am still testing it in Matlab and will come back with solution soon, I hope so! Feb 28, 2023 at 12:50
• This answer explains differential addition. Basically, you add point $P$ and $Q$ also knowing $R=Q-P$ (or is it $R=P-Q$) in advance. Unfortunately I can't immediately tell per what order indices $1/2/3$ map to $P/Q/R$, else I would make that an answer. Also I think the question's formula assumes $Z_1=1$, and otherwise you need these slightly more complex formulas (and more modular reductions). If you solved your problem already, please make and accept an answer!
– fgrieu
Mar 28, 2023 at 8:08