-snip-
I have a question.
If the private key is 3 ... do I need to change the formula this way?
R = P+P+P
c = 4*P.x*Px*invert(3*P.y) % modulo
R.x = (c*c - 3*P.x) % modulo
No, formula is ALWAYS the same. That was a formula for double the point:
c = 3*P.x*Px*invert(2*P.y) % modulo
R.x = (c*c - 2*P.x) % modulo
R.y = (c*(P.x - R.x) - P.y) % modulo
If you want to add 2 points P and Q (2 different non-zero Points) there is another formula for R = P + Q:
dx = (Q.x - P.x) % modulo
dy = (Q.y - P.y) % modulo
c = dy * invert(dx) % modulo
R.x = (c*c - P.x - Q.x) % modulo
R.y = (c*(P.x - R.x) - P.y) % modulo
For addition it does not matter if you make P + Q or Q + P, teh result will be the same.
Also, keep in mind that in elliptic curve scalar addition there are only scalar addition and scalar doubling are determined. No, direct multiplication, or no direct substraction, etc. For multiplication, the factor is splited in order to make only doublings and additions.
So, for private key = 3 you have: 3=2+1, and the public key will be 3G = 2G + 1G = doubled G + G, so first of all you should double G and receive 2G (1st formula), and then make the addition of 2 points 2G and G (2dn formula) and finally you will have 3G or pubblic key for pk = 3.
The same for every number. For example, if you want to find the public key for 13, you should present it in this form: 13 = 8 + 4 + 1 = 2^3 + 2^2 + 1, and now calculate public key for every part (for 2^2 it is doubling G, and then doubling te received result again; for 2^3 it is the dubling G 3 times, anf for 1 it is just G); as soon as you have all 3 public keys you should use addition formula 2 times: add 2^3 and 2^2 and then add the received result with G. Finally you will have the public key for pk = 13
Actully all the scripts do the same work: doubling points and adding them, nothing else. Only doubling and addition.
Good luck with manual calcualtions
