Title: OFF TOPIC Post by: ricardosuperx on May 02, 2020, 11:37:49 PM HELLO PEOPLE!
I would like a good explanation of how public keys are generated. EQUATION OR FORMULA y^2 = x^3 + 7 P = k * G X = c^2 – 2px Y = c (px – rx) – py Private key: 1 Public key compressed : X = 0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 So it should be ... Private key: 2 Public key compressed: X =02F37CCCFDF3B97758AB40C52B9D0E160E0537F9B65B9C51B2B3E502B62DF02F30 Why public key compressed of 2 is: X = 02C6047F9441ED7D6D3045406E95C07CD85C778E4B8CEF3CA7ABAC09B95C709EE5? Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on May 03, 2020, 12:29:46 AM It does not work in this way.
Keep in mind main thing: private key is a number (just integer), but public key is a point with x and y coordinates. So you in your example public key was not correct for private key 1. For private key 1 the public key is: 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 where 04 is a prefix for uncompressed key, green part is X-coordinate and blue part is Y-coordinate. The compressed key contains only X coordinate with the prefix 02/03 (02 for Y even, and 03 for Y odd), because Y could be received from the formula y^2 = x^3 + 7, so no need to keep Y. The compressed key so will be: 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 In your example you wrote only X coordinate for public key, it was not correct. Prefix 02 should also be there in order to know both coordinates. Also, you should know that there is a basis point which was determined for elliptic curve selected for bitcoin. Basis point is usually written as G, and has coordinates: Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 Now the public key for every pk is pk*G, so for 1 public key 1*G - actually the G basis point itself. For pk=2 the public key is 2*G = G + G, so you should perform scalar addition for basis point with itself (you should use point doubling). For pk=3 you just add the publik key for pk=2 with basis point G And so on For more details have a look at parrt 4 of this reading: https://pdfslide.net/documents/introduction-to-bitcoin-and-ecdsa.html Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on May 03, 2020, 12:43:48 AM I'm doing this:
Private key 2: G2 * 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 Public key compressed: X = 02F37CCCFDF3B97758AB40C52B9D0E160E0537F9B65B9C51B2B3E502B62DF02F30 I'm really sad ... I'm trying to learn and the moderator deleted my previous post ... Disappointed! Thanks MrFreeDragon for the explanation Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on May 03, 2020, 01:17:26 AM -snip- Thanks for the answer. I will correct my question. I just wanted to understand the G + G2 point duplication part ... The public key of 2, X =0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798. But for me: X = 02f37cccfdf3b97758ab40c52b9d0e160e0537f9b65b9c51b2b3e502b62df02f30 If you want to doule point P in order to receive R = P + P, you should make the following: 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 modulo = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F For your case with P = G = Point (Gx, Gy) where: Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 We have the following: invert(2*P.y) = 0xb7e31a064ed74d314de79011c5f0a46ac155602353dc3d340fbeaeec9767a6a6 c = 0xcb35b28428101a303eb9d1235992ac63f58857c2f631ee6936d3aebbeddcd1b1 R.x = (c*c - 2*Gx) % modulo = 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 R.y = 0x1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a So we have R.x and R.y of the public key 2G = G + G (public key for private key = 2), and it is written in compressed format like: 02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on May 03, 2020, 01:29:58 AM I thank you very much!
I'm trying here, I would like to do and understand without scripts or programs. I want to learn manually. I am open to further explanation. Thank MrFreeDragon Title: Re: Private key to public key (TUTORIAL) Post by: tbct_mt2 on May 03, 2020, 03:10:40 AM You can read this book, Mastering Bitcoin (https://github.com/bitcoinbook/bitcoinbook), of Andreas M. Antonopoulos, and the chapter 4 is what you need
Chapter 4: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch04.asciidoc Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on May 03, 2020, 02:53:33 PM -snip- Thanks for the answer. I will correct my question. I just wanted to understand the G + G2 point duplication part ... The public key of 2, X =0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798. But for me: X = 02f37cccfdf3b97758ab40c52b9d0e160e0537f9b65b9c51b2b3e502b62df02f30 If you want to doule point P in order to receive R = P + P, you should make the following: 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 modulo = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F For your case with P = G = Point (Gx, Gy) where: Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 We have the following: invert(2*P.y) = 0xb7e31a064ed74d314de79011c5f0a46ac155602353dc3d340fbeaeec9767a6a6 c = 0xcb35b28428101a303eb9d1235992ac63f58857c2f631ee6936d3aebbeddcd1b1 R.x = (c*c - 2*Gx) % modulo = 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 R.y = 0x1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a So we have R.x and R.y of the public key 2G = G + G (public key for private key = 2), and it is written in compressed format like: 02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 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 Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on May 03, 2020, 02:58:48 PM You can read this book, Mastering Bitcoin (https://github.com/bitcoinbook/bitcoinbook), of Andreas M. Antonopoulos, and the chapter 4 is what you need I read. Very interesting! Thanks, but I still have questionsChapter 4: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch04.asciidoc Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on May 03, 2020, 03:28:34 PM -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 :o Title: Re: Private key to public key (TUTORIAL) Post by: joinfree on May 03, 2020, 06:07:21 PM Wait a minute, so are you guys suggesting that you can actually calculate or deduce the private keys of someone by just looking at the public key? I'm lost maybe a bit of clarification would help. Or I am not getting that the OP is trying to say.
Title: Re: Private key to public key (TUTORIAL) Post by: Review Master on May 03, 2020, 07:15:33 PM Wait a minute, so are you guys suggesting that you can actually calculate or deduce the private keys of someone by just looking at the public key? I'm lost maybe a bit of clarification would help. Or I am not getting that the OP is trying to say. No that's not actually going to happen. Because this is just one integer public key, but in reality there are more integer in your private key. No scripts can deduce the private keys of someone. Even if anyone wants to do this, he/she needs a quantum computer with a minimum of 1000 qubits to expose any private key from any algorithm. In this current time, only IBM has 50 qubits of a quantum computer and Google (cooperating with NASA) has 53 qubits of quantum computer. Thought D-wave have 2000 qubits of quantum computer, but that's used only for optimization not for general purpose. So, it's will take more time to break bitcoin or other crypto-currencies private key. Also by the time passed, there will be a solution for it too. :DTitle: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on May 15, 2020, 02:44:51 PM Wait a minute, so are you guys suggesting that you can actually calculate or deduce the private keys of someone by just looking at the public key? I'm lost maybe a bit of clarification would help. Or I am not getting that the OP is trying to say. I just want to understand the math behind Bitcoin in a simple way ;)Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on May 15, 2020, 02:49:07 PM Wait a minute, so are you guys suggesting that you can actually calculate or deduce the private keys of someone by just looking at the public key? I'm lost maybe a bit of clarification would help. Or I am not getting that the OP is trying to say. No that's not actually going to happen. Because this is just one integer public key, but in reality there are more integer in your private key. No scripts can deduce the private keys of someone. Even if anyone wants to do this, he/she needs a quantum computer with a minimum of 1000 qubits to expose any private key from any algorithm. In this current time, only IBM has 50 qubits of a quantum computer and Google (cooperating with NASA) has 53 qubits of quantum computer. Thought D-wave have 2000 qubits of quantum computer, but that's used only for optimization not for general purpose. So, it's will take more time to break bitcoin or other crypto-currencies private key. Also by the time passed, there will be a solution for it too. :DTitle: Re: Private key to public key (TUTORIAL) Post by: BrewMaster on May 15, 2020, 03:30:40 PM I just want to understand the math behind Bitcoin in a simple way ;) well that math is not very simple to learn it that easily. there is a lot of new concepts involved and the whole algorithm (elliptic curve cryptography) also has certain complexity to it. but i have found that this page here explains things in simpler terms that could get you started on understanding the whole thing, specially while looking at the curve shapes included helps with understanding the characteristics of elliptic curves: https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/ Title: Re: Private key to public key (TUTORIAL) Post by: Review Master on May 15, 2020, 05:36:38 PM I just want to understand the math behind Bitcoin in a simple way ;) you can check this sources to learn more. I am also a learner and happy to be here. https://blog.cloudflare.com/a-relatively-easy-to-understand-primer-on-elliptic-curve-cryptography/ For more details have a look at parrt 4 of this reading: https://pdfslide.net/documents/introduction-to-bitcoin-and-ecdsa.html Title: Re: Private key to public key (TUTORIAL) Post by: archyone on May 27, 2020, 05:39:29 AM -snip- Thanks for the answer. I will correct my question. I just wanted to understand the G + G2 point duplication part ... The public key of 2, X =0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798. But for me: X = 02f37cccfdf3b97758ab40c52b9d0e160e0537f9b65b9c51b2b3e502b62df02f30 If you want to doule point P in order to receive R = P + P, you should make the following: 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 modulo = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F For your case with P = G = Point (Gx, Gy) where: Gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 We have the following: invert(2*P.y) = 0xb7e31a064ed74d314de79011c5f0a46ac155602353dc3d340fbeaeec9767a6a6 c = 0xcb35b28428101a303eb9d1235992ac63f58857c2f631ee6936d3aebbeddcd1b1 R.x = (c*c - 2*Gx) % modulo = 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 R.y = 0x1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a So we have R.x and R.y of the public key 2G = G + G (public key for private key = 2), and it is written in compressed format like: 02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 Hello, Thanks for your explanation I'm confuse with this part : c = 3*P.x*Px*invert(2*P.y) % modulo How get invert(2*P.y) = 0xb7e31a064ed74d314de79011c5f0a46ac155602353dc3d340fbeaeec9767a6a6 ?? Can someone provide an explanation or simply a python formula, is it the inverse modular ? Thanks in advance Title: Re: Private key to public key (TUTORIAL) Post by: BrewMaster on May 27, 2020, 05:51:03 PM How get invert(2*P.y) = the full name is Modular Multiplicative Inverse and to compute ModInverse(2*P.y) you have to find a value that when multiplied by your value and divided by the prime gives 1. you can read more about it on wikipedia: https://en.wikipedia.org/wiki/Modular_multiplicative_inverse look at the examples below that. the computation uses the extended Euclidean algorithm. here is a python example: https://stackoverflow.com/a/9758173/10401748 Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on May 27, 2020, 06:28:03 PM -snip- I'm confuse with this part : c = 3*P.x*Px*invert(2*P.y) % modulo How get invert(2*P.y) = 0xb7e31a064ed74d314de79011c5f0a46ac155602353dc3d340fbeaeec9767a6a6 ?? -snip- As was explained above, the inverse for k by modulo is such value mwhere (m*k) by modulo is equal to 1. The best way for python is to use library gmpy2 and its function gmpy2.invert(k,p) which returns the inverse value to k by modulo = p. This function is the best for python and approx. 50 times faster than any other self made calculations. For ubuntu for example you can easily install it: Code: sudo apt update If it is not in repository, you can download gmpy2 from here (pls, check the correct python version): https://www.lfd.uci.edu/~gohlke/pythonlibs/#gmpy and install it in this way (example for python ver 3.7): Code: python -m pip install gmpy2-2.0.8-cp37-cp37m-win_amd64.whl If you do not want to use the gmpy2 libriary (however it is the best way), you can also use this self made inversion function: Code: def egcd (a, b): The function inversion requires 2 parameters: m and n, where n is the modulo and m is the number for which you would like to calculate the inverse. Title: Re: Private key to public key (TUTORIAL) Post by: archyone on June 05, 2020, 11:34:03 AM Thanks to MrFreedragon and BrewMaster for the explanations. However I still have a question on the generation of public key with a private key other than 1 or 2 or 13 like the examples.
MrFreedragon say : "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" My question is : why 13 = 8 + 4 +1 ? is 4 + 4 + 4 + 1 give the same result or must there be a certain rule ? Not sure and i can't retreive the post but it seem i read something with the private key in it's binary form ? Sorry for my noob question ^^ but bitcoin is really more complicated than I thought at the start ^^ Title: Re: Private key to public key (TUTORIAL) Post by: BrewMaster on June 05, 2020, 05:24:51 PM My question is : why 13 = 8 + 4 +1 ? is 4 + 4 + 4 + 1 give the same result or must there be a certain rule ? they are the same.Quote Not sure and i can't retreive the post but it seem i read something with the private key in it's binary form ? that's the idea. one of the methods to compute public key (which is multiplying the key numeric value by generator point) is that key (shown as d) is going to be split into smaller powers of 2 parts (d0 + 2d1+...) then for each 1 an addition then a doubling occurs and for each 0 only point double is performed.https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on June 05, 2020, 09:24:19 PM -snip- My question is : why 13 = 8 + 4 +1 ? is 4 + 4 + 4 + 1 give the same result or must there be a certain rule ? Not sure and i can't retreive the post but it seem i read something with the private key in it's binary form ? -snip- Your example with 13 will give the same result. You can also calculate 13 as 1 + 1 + 1 + 1 + ... + 1 + 1 (13 times), but here you should perform 12 additions. As for the private key in binary form - I made a tool to play with binary numbers: https://bitcointalk.org/index.php?topic=5187401 That tool is very nice for learning purposes. And also good to create real wallets if you use physical coin for your random entropy source. Every binary number could be represented as c255*2^255 + c254*2^254 + c253*2^253 + ... + c3*2^3 + c2^2 + c1*2 + c0, where coefficients c0, c1, c2, ... c254, c255 represent bit values (1 or 0). It is actually your binary number. So in order to calculate public keys for various large binary numbers you can easily make the pre-calculations of 256 public keys for numbers 1, 2, 2^2, 2^3, 2^4, 2^5, ... 2^254, 2^255 and later just make up to 255 additions between pre-calculated public keys. Title: Re: Private key to public key (TUTORIAL) Post by: archyone on August 27, 2020, 07:24:44 PM Hello everyone, good! thanks to the help of MrFreeDragon and BrewMaster I now have a good basis for adding 2 points on an elliptical curve.
As a reminder : If you want to double point P in order to receive R = P + P, you should make the following: 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 modulo = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F and 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 I have now no problem with this but as you can imagine, I still have 1 problem ^^, certainly due to my approximate understanding of English I am unable to find a formula for point to point substraction. Is this also possible? Thanks in advance (again^^) Title: Re: Private key to public key (TUTORIAL) Post by: BrewMaster on August 28, 2020, 02:07:34 AM I have now no problem with this but as you can imagine, I still have 1 problem ^^, certainly due to my approximate understanding of English I am unable to find a formula for point to point substraction. Is this also possible? there is no special formula for point subtraction as far as i know. instead the P-Q is simply defined as P+(-Q) (same as addition) and -Q or negative of a point is defined as negating its y coordinate. or in other words -Q(x,y) = Q(x,-y) and since we don't use negative numbers in modular arithmetic -y becomes P-y where P is curve's prime. Title: Re: Private key to public key (TUTORIAL) Post by: archyone on August 28, 2020, 11:26:11 AM there is no special formula for point subtraction as far as i know. instead the P-Q is simply defined as P+(-Q) (same as addition) and -Q or negative of a point is defined as negating its y coordinate. or in other words -Q(x,y) = Q(x,-y) and since we don't use negative numbers in modular arithmetic -y becomes P-y where P is curve's prime. oOO !! wonderfully explained, first test -> total success .. I understood the first time when research for several weeks had not led to much. Many thanks to you BrewMaster (again ^^) It is this notation (-y becomes P-y where P is curve's prime) that I have not seen anywhere that I am lacking. Title: Re: Private key to public key (TUTORIAL) Post by: bytcoin on August 29, 2020, 07:38:17 PM -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 If the formula is always the same, All public keys will also always be the same! "Where am I wrong? (dx, dy, c, R.x, R.y, Q.x Q.y, P.x, P.y)Can someone explain to me what are this? I think Rx and Ry are the coordinates of the public key, right? Title: Re: Private key to public key (TUTORIAL) Post by: BrewMaster on August 30, 2020, 04:02:01 AM If the formula is always the same, All public keys will also always be the same! "Where am I wrong? they aren't the same because this formula is called different number of times depending on the private key. in simple terms imagine if the formula was this: x+1 and you always called it with the same x (like you do with the generator point). if you use it with x=5 and call it 3 times (private key equal to 3) you get 8 and if you call it 6 times (private key equal to 6) you get 11 and so on. Title: Re: Private key to public key (TUTORIAL) Post by: archyone on September 05, 2020, 10:33:20 AM If the formula is always the same, All public keys will also always be the same! "Where am I wrong?
(dx, dy, c, R.x, R.y, Q.x Q.y, P.x, P.y)Can someone explain to me what are this? I think Rx and Ry are the coordinates of the public key, right? [/quote] ok, I will try to explain as simply as possible because it is true that I myself struggled to understand the system. So it is a question here of adding 2 points (not the same). In this example we use : first point: (all values are in décimal for a better comprehension) X coordinate: 21262057306151627953595685090280431278183829487175876377991189246716355947009 (it is Qx) Y coordinate: 41749993296225487051377864631615517161996906063147759678534462689479575333124 (it is Qy) The Private key for this point is 0000000000000000000000000000000000000000000000000000000000000008 second point to add: X coordinate: 89565891926547004231252920425935692360644145829622209833684329913297188986597 (it is Px) Y coordinate: 12158399299693830322967808612713398636155367887041628176798871954788371653930 (it is Py) The Private key for this point is 0000000000000000000000000000000000000000000000000000000000000002 So to add the 1st point to the second we use the formula : (here modulo is 115792089237316195423570985008687907853269984665640564039457584007908834671663 ) 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 in our example we have dx = (21262057306151627953595685090280431278183829487175876377991189246716355947009 - 89565891926547004231252920425935692360644145829622209833684329913297188986597) % modulo dx = 47488254616920819145913749673032646770809668323194230583764443341328001632075 dy = (41749993296225487051377864631615517161996906063147759678534462689479575333124 - 12158399299693830322967808612713398636155367887041628176798871954788371653930) % modulo dy = 29591593996531656728410056018902118525841538176106131501735590734691203679194 invert of dx = 70279122268919195963430815486314537773961171454828771794853116552210630553734 c = dy * invert(dx) % modulo c = 16132032934385503768504319366562120314980927452732756733183380715276156205226 So the new point (8 + 2) R.x = (c*c - P.x - Q.x) % modulo R.x --> X coordinate of (8+2) = 72488970228380509287422715226575535698893157273063074627791787432852706183111 R.y = (c*(P.x - R.x) - P.y) % modulo R.y --> Y coordinate of (8+2) = 62070622898698443831883535403436258712770888294397026493185421712108624767191 If we check these coordinates, we find that it corresponds to the private key: 000000000000000000000000000000000000000000000000000000000000000a (10) There you go, I hope I was as clear as possible and apologies for my broken English ^^ Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on September 13, 2020, 05:22:01 PM I learned to double the point, but I cannot calculate the public keys of the private keys in sequence
Duplication of points; Compressed public key; In decimal; Equation: c = (3px^2 + a) / 2py rx = c^2 – 2px Prime Modulo: 115792089237316195423570985008687907853269984665640564039457584007908834671663 Base Point: (55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424) Order: 115792089237316195423570985008687907852837564279074904382605163141518161494337 Private key: 0000000000000000000000000000000000000000000000000000000000000002 c= 3px^2 + a) / 2py c=(3*55066263022277343669578718895168534326250603453777594175500187360389116729240^2)/2*32670510020758816978083085130507043184471273380659243275938904335757337482424 c=(3*60300556597753154781239923047219078515410877540607532238537983597388018023497)/2*32670510020758816978083085130507043184471273380659243275938904335757337482424 c=65109580555943268920148784132969327692962647956182032676156366784255219398828/2*32670510020758816978083085130507043184471273380659243275938904335757337482424 c=65109580555943268920148784132969327692962647956182032676156366784255219398828/65341020041517633956166170261014086368942546761318486551877808671514674964848 c=91914383230618135761690975197207778399550061809281766160147273830617914855857 rx=(91914383230618135761690975197207778399550061809281766160147273830617914855857^2)-2*55066263022277343669578718895168534326250603453777594175500187360389116729240 rx=83906328733785496146839373207584853159875368071536834145227120626166587773414-2*55066263022277343669578718895168534326250603453777594175500187360389116729240 rx=83906328733785496146839373207584853159875368071536834145227120626166587773414-110132526044554687339157437790337068652501206907555188351000374720778233458480 rx=89565891926547004231252920425935692360644145829622209833684329913297188986597 rx Compressed in hex = 02c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 Now i would like to understand how to do for private key 3 Can someone do a tutorial like I did IN DECIMAL OF PRIVATE KEY 3 Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on September 13, 2020, 05:59:16 PM If the formula is always the same, All public keys will also always be the same! "Where am I wrong? (dx, dy, c, R.x, R.y, Q.x Q.y, P.x, P.y)Can someone explain to me what are this? I think Rx and Ry are the coordinates of the public key, right? ok, I will try to explain as simply as possible because it is true that I myself struggled to understand the system. So it is a question here of adding 2 points (not the same). In this example we use : first point: (all values are in décimal for a better comprehension) X coordinate: 21262057306151627953595685090280431278183829487175876377991189246716355947009 (it is Qx) Y coordinate: 41749993296225487051377864631615517161996906063147759678534462689479575333124 (it is Qy) The Private key for this point is 0000000000000000000000000000000000000000000000000000000000000008 second point to add: X coordinate: 89565891926547004231252920425935692360644145829622209833684329913297188986597 (it is Px) Y coordinate: 12158399299693830322967808612713398636155367887041628176798871954788371653930 (it is Py) The Private key for this point is 0000000000000000000000000000000000000000000000000000000000000002 So to add the 1st point to the second we use the formula : (here modulo is 115792089237316195423570985008687907853269984665640564039457584007908834671663 ) 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 in our example we have dx = (21262057306151627953595685090280431278183829487175876377991189246716355947009 - 89565891926547004231252920425935692360644145829622209833684329913297188986597) % modulo dx = 47488254616920819145913749673032646770809668323194230583764443341328001632075 dy = (41749993296225487051377864631615517161996906063147759678534462689479575333124 - 12158399299693830322967808612713398636155367887041628176798871954788371653930) % modulo dy = 29591593996531656728410056018902118525841538176106131501735590734691203679194 invert of dx = 70279122268919195963430815486314537773961171454828771794853116552210630553734 c = dy * invert(dx) % modulo c = 16132032934385503768504319366562120314980927452732756733183380715276156205226 So the new point (8 + 2) R.x = (c*c - P.x - Q.x) % modulo R.x --> X coordinate of (8+2) = 72488970228380509287422715226575535698893157273063074627791787432852706183111 R.y = (c*(P.x - R.x) - P.y) % modulo R.y --> Y coordinate of (8+2) = 62070622898698443831883535403436258712770888294397026493185421712108624767191 If we check these coordinates, we find that it corresponds to the private key: 000000000000000000000000000000000000000000000000000000000000000a (10) There you go, I hope I was as clear as possible and apologies for my broken English ^^ [/quote] That's what I wanted! Could you make private key 3? Title: Re: Private key to public key (TUTORIAL) Post by: archyone on September 13, 2020, 09:21:23 PM That's what I wanted! Could you make private key 3? We must not forget that there are two formulasThe one you used to find the point corresponding to the private key: 2 (or rather 0000000000000000000000000000000000000000000000000000000000000002 to be more precise) it is Duplication of points. You did it in your example with the base point--> 1 + 1 =2 (but that could be another point) To go now with 3 we need to do --> 2 + 1 = 3 (we have now 2 différents points and we can't doubling them) For that you need to use the second formula: modulo = 115792089237316195423570985008687907853269984665640564039457584007908834671663 Px = 89565891926547004231252920425935692360644145829622209833684329913297188986597 (x coordinate point 2) Py = 12158399299693830322967808612713398636155367887041628176798871954788371653930 (y coordinate point 2) Qx = 55066263022277343669578718895168534326250603453777594175500187360389116729240 (x coordinate point 1) not because it is the base point, just because it is the point n°1 Qy = 32670510020758816978083085130507043184471273380659243275938904335757337482424 (y coordinate point 1) dx = (Qx - Px) % modulo --> 34499628904269660561674201530767158034393542375844615658184142552908072257357 dy = (Qy - Py) % modulo --> 95279978516251208768455708490894263304954079172022948940317551626939868843169 c = dy * invert(dx) % modulo --> 23578750110654438173404407907450265080473019639451825850605815020978465167024 Rx = (c*c - Px - Qx) % modulo --> 112711660439710606056748659173929673102114977341539408544630613555209775888121 (x coordinate of point (2+1 =3) Ry = (c*(Px - Rx) - Py) % modulo --> 25583027980570883691656905877401976406448868254816295069919888960541586679410 (y coordinate of point (2+1 =3) Can't explain better Title: Re: Private key to public key (TUTORIAL) Post by: BASE16 on September 13, 2020, 11:14:07 PM You are mixing BASE16 with BASE10 there :D
Your private key = 0x0000000000000000000000000000000000000000000000000000000000000002 It's called BITcoin not BYTEcoin !! or even INTcoin hahaha ::) Since this is a tutorial you can not really leave out the part of the binary private key so here goes. :) You start with a 256 Bits BASE2 Binary Private Key. (Aka. the BIT coin flips) A bit is either 1 or 0 no in between. Code:
Then you can use the following table which is about point doubling: Code:
The first number in the list is the bit number, and the second number is the multiplier, the number of times you will add the generator point to itself later on. It's important to know that we start with bit 256, this is the last bit of the binary private key so you have to read the private key backwards and start with the last bit first. Adding all the numbers is simple: If the bit value is true or a '1' then you will write down the multiplier value and if it is false or a '0' you will write down nothing and move to the next bit. You do this for all the bits and when you are done, you simply add all these multiplier values together, and this will give you the number of times you have to add the generator point to itself to get to the public key point. Code:
Let's calculate the private key in the example above and remember we start with the last bit first: Code:
We now add up all these numbers, and this gives us a total of privateKeyBase10 = 81425905913881293233417886915456929825803636934140198496261481046664027716260 in BASE10 Or a total of privateKeyBase16 = b4056df6691f8dc72e56302ddad345d65fead3ead9299609a826e2344eb63aa4 in BASE16, which is the hexadecimal private key. https://i.ibb.co/VtmrQ4V/bitaddress.png (https://ibb.co/R9yZBw2) This is the private key number in a format that few people are familiar with but it can also be represented in various WIF Formats depending on the compression parameter: WIF: 5KBZytdkzttdedEB7xLom6YnHRCVTNQPUrJiTDJKS7VJUbiX6Di // uncompressed WIF: L3Fea6uFCY2tm4u9fhGRPdVGsToibPUEDvdBxhHSMqdv8odQMTAZ // compressed As most of us know the full uncompressed public key will start with prefix '04' and have both the X and Y coordinates. The compressed public key only holds the X coordinate, and it can be odd, or even. Public keys of the even type start with a prefix '2' while public keys of the odd type start with a prefix '03' You can discover, or calculate the key type of the compressed public key by looking at the least significant bit of the Y coordinate of the public key. It's important to note that this is not regular multiplication but epileptic curve multiplication. More about the algorithm here: https://paulmillr.com/posts/noble-secp256k1-fast-ecc/ (https://paulmillr.com/posts/noble-secp256k1-fast-ecc/) Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on September 13, 2020, 11:51:30 PM -snip- Now i would like to understand how to do for private key 3 Can someone do a tutorial like I did IN DECIMAL OF PRIVATE KEY 3 Formula for point doubling is: def mul2(Pmul2, p = modulo): R = Point(0,0) c = 3*Pmul2.x*Pmul2.x*gmpy2.invert(2*Pmul2.y, p) % p R.x = (c*c-2*Pmul2.x) % p R.y = (c*(Pmul2.x - R.x)-Pmul2.y) % p return R Formula for points addition is (used for different points only): def add(Padd, Q, p = modulo): R = Point() dx = (Q.x - Padd.x) % p dy = (Q.y - Padd.y) % p c = dy * gmpy2.invert(dx, p) % p R.x = (c*c - Padd.x - Q.x) % p R.y = (c*(Padd.x - R.x) - Padd.y) % p return R gmpy2.invert here is the inverse calculation. Now you can easily calculate public key for private number 2 - just double the basis point G. In order to calculate the private key for private number 3 you can apply addition for two points - point receive in first stage (doubling of G) and G (because 3 = 1*2 + 1, where 1 is the basis point G): Code: >>> PG.x, PG.y Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on September 14, 2020, 12:54:27 PM That's what I wanted! Could you make private key 3? We must not forget that there are two formulasThe one you used to find the point corresponding to the private key: 2 (or rather 0000000000000000000000000000000000000000000000000000000000000002 to be more precise) it is Duplication of points. You did it in your example with the base point--> 1 + 1 =2 (but that could be another point) To go now with 3 we need to do --> 2 + 1 = 3 (we have now 2 différents points and we can't doubling them) For that you need to use the second formula: modulo = 115792089237316195423570985008687907853269984665640564039457584007908834671663 Px = 89565891926547004231252920425935692360644145829622209833684329913297188986597 (x coordinate point 2) Py = 12158399299693830322967808612713398636155367887041628176798871954788371653930 (y coordinate point 2) Qx = 55066263022277343669578718895168534326250603453777594175500187360389116729240 (x coordinate point 1) not because it is the base point, just because it is the point n°1 Qy = 32670510020758816978083085130507043184471273380659243275938904335757337482424 (y coordinate point 1) dx = (Qx - Px) % modulo --> 34499628904269660561674201530767158034393542375844615658184142552908072257357 dy = (Qy - Py) % modulo --> 95279978516251208768455708490894263304954079172022948940317551626939868843169 c = dy * invert(dx) % modulo --> 23578750110654438173404407907450265080473019639451825850605815020978465167024 Rx = (c*c - Px - Qx) % modulo --> 112711660439710606056748659173929673102114977341539408544630613555209775888121 (x coordinate of point (2+1 =3) Ry = (c*(Px - Rx) - Py) % modulo --> 25583027980570883691656905877401976406448868254816295069919888960541586679410 (y coordinate of point (2+1 =3) Can't explain better Order: 115792089237316195423570985008687907852837564279074904382605163141518161494337 Base Point: (55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424) Modulo: 115792089237316195423570985008687907853269984665640564039457584007908834671663 Private key: 0000000000000000000000000000000000000000000000000000000000000003 Point addition:(2G+1G =3G) Compressed public key; In decimal; Equation: c = (qy – py) / (qx – px) rx = c^2 – px – qx px = 89565891926547004231252920425935692360644145829622209833684329913297188986597 py = 12158399299693830322967808612713398636155367887041628176798871954788371653930 qx = 55066263022277343669578718895168534326250603453777594175500187360389116729240 qy = 32670510020758816978083085130507043184471273380659243275938904335757337482424 c = 32670510020758816978083085130507043184471273380659243275938904335757337482424- 12158399299693830322967808612713398636155367887041628176798871954788371653930= 20512110721064986655115276517793644548315905493617615099140032380968965828494 c = 55066263022277343669578718895168534326250603453777594175500187360389116729240- 89565891926547004231252920425935692360644145829622209833684329913297188986597= 81292460333046534861896783477920749818876442289795948381273441455000762414306 c = 20512110721064986655115276517793644548315905493617615099140032380968965828494/ 81292460333046534861896783477920749818876442289795948381273441455000762414306= 23578750110654438173404407907450265080473019639451825850605815020978465167024 c = 23578750110654438173404407907450265080473019639451825850605815020978465167024 rx = 23578750110654438173404407907450265080473019639451825850605815020978465167024^2 - 89565891926547004231252920425935692360644145829622209833684329913297188986597- 55066263022277343669578718895168534326250603453777594175500187360389116729240 rx = 25759636913902563110438328477658084082469757293658084474899962813078412260632- 34499628904269660561674201530767158034393542375844615658184142552908072257357 rx = 107052097246949097972335111955578833901346199583454032856173404268079174674938 rx hex = 0xecad56ff86123a68f47514b195ab6837ba69c1fbdf0beb6339e6f3caead069fa Now I will try to calculate the private key 0000000000000000000000000000000000000000000000000000000000000005 Title: Re: Private key to public key (TUTORIAL) Post by: BASE16 on September 14, 2020, 01:18:48 PM Private key 3 is 3 * G
Add the Generator 3 times. 0x02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9 Point 1 {x: 55066263022277343669578718895168534326250603453777594175500187360389116729240n, y: 32670510020758816978083085130507043184471273380659243275938904335757337482424n} X: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 Y: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 Point 2 {x: 89565891926547004231252920425935692360644145829622209833684329913297188986597n, y: 12158399299693830322967808612713398636155367887041628176798871954788371653930n} X: 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 Y: 0x1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a Point 3 {x: 112711660439710606056748659173929673102114977341539408544630613555209775888121n, y: 25583027980570883691656905877401976406448868254816295069919888960541586679410n} X: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Y: 0x388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on September 14, 2020, 01:56:03 PM Private key 3 is 3 * G Corrected, thanks!Add the Generator 3 times. 0x02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9 Point 1 {x: 55066263022277343669578718895168534326250603453777594175500187360389116729240n, y: 32670510020758816978083085130507043184471273380659243275938904335757337482424n} X: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 Y: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 Point 2 {x: 89565891926547004231252920425935692360644145829622209833684329913297188986597n, y: 12158399299693830322967808612713398636155367887041628176798871954788371653930n} X: 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 Y: 0x1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a Point 3 {x: 112711660439710606056748659173929673102114977341539408544630613555209775888121n, y: 25583027980570883691656905877401976406448868254816295069919888960541586679410n} X: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Y: 0x388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 X: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Y: 0x388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 EDITED:THIS IS THE KEY PUBLIC OF THE PRIVATE KEY 0000000000000000000000000000000000000000000000000000000000000003 Title: Re: Private key to public key (TUTORIAL) Post by: BASE16 on September 14, 2020, 02:19:04 PM Private key 3 is 3 * G Corrected, thanks!Add the Generator 3 times. 0x02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9 Point 1 {x: 55066263022277343669578718895168534326250603453777594175500187360389116729240n, y: 32670510020758816978083085130507043184471273380659243275938904335757337482424n} X: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 Y: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 Point 2 {x: 89565891926547004231252920425935692360644145829622209833684329913297188986597n, y: 12158399299693830322967808612713398636155367887041628176798871954788371653930n} X: 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 Y: 0x1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a Point 3 {x: 112711660439710606056748659173929673102114977341539408544630613555209775888121n, y: 25583027980570883691656905877401976406448868254816295069919888960541586679410n} X: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Y: 0x388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 Now What do I do with: X: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Y: 0x388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 ? What do you want to do with it ? You can turn it into uncompressed public key: publicKey = '04' + X + Y publicKey = 04f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de 8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 Or turn it into a even compressed public key: publicKey = '02' + X publicKey = 02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Or turn it into a odd compressed public key: publicKey = '03' + X publicKey = 03f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 One of the last two is invalid. You have to look at the least significant bit of Y to see if its odd or even. Y = 0x388F7B0F632DE8140FE337E62A37F3566500A99934C2231B6CB9FD7584B8E672 Y = 0b11100010001111011110110000111101100011001011011110100000010100000011111110001 1001101111110011000101010001101111111001101010110011001010000000010101001100110 0100110100110000100010001100011011011011001011100111111101011101011000010010111 0001110011001110010 The last bit is even so it's '02' You can also convert it to WIF: 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreB1FQ8BZ uncompressed KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU74sHUHy8S compressed And you can calculate various addresses but that is far past private to pubkey :) Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on September 14, 2020, 02:43:58 PM Private key 3 is 3 * G Corrected, thanks!Add the Generator 3 times. 0x02F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9 Point 1 {x: 55066263022277343669578718895168534326250603453777594175500187360389116729240n, y: 32670510020758816978083085130507043184471273380659243275938904335757337482424n} X: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 Y: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 Point 2 {x: 89565891926547004231252920425935692360644145829622209833684329913297188986597n, y: 12158399299693830322967808612713398636155367887041628176798871954788371653930n} X: 0xc6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5 Y: 0x1ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a Point 3 {x: 112711660439710606056748659173929673102114977341539408544630613555209775888121n, y: 25583027980570883691656905877401976406448868254816295069919888960541586679410n} X: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Y: 0x388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 Now What do I do with: X: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Y: 0x388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 ? What do you want to do with it ? You can turn it into uncompressed public key: publicKey = '04' + X + Y publicKey = 04f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de 8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 Or turn it into a even compressed public key: publicKey = '02' + X publicKey = 02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Or turn it into a odd compressed public key: publicKey = '03' + X publicKey = 03f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 One of the last two is invalid. You have to look at the least significant bit of Y to see if its odd or even. Y = 0x388F7B0F632DE8140FE337E62A37F3566500A99934C2231B6CB9FD7584B8E672 Y = 0b11100010001111011110110000111101100011001011011110100000010100000011111110001 1001101111110011000101010001101111111001101010110011001010000000010101001100110 0100110100110000100010001100011011011011001011100111111101011101011000010010111 0001110011001110010 The last bit is even so it's '02' You can also convert it to WIF: 5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreB1FQ8BZ uncompressed KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU74sHUHy8S compressed And you can calculate various addresses but that is far past private to pubkey :) SORRY! I convert in decimal: 02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9, instead of: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 ::) Now I will try to calculate the private key 0000000000000000000000000000000000000000000000000000000000000005 Title: Re: Private key to public key (TUTORIAL) Post by: BASE16 on September 14, 2020, 02:56:53 PM SORRY! I convert in decimal: 02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9, instead of: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 ::) It's both the same in BASE16. The first one is public key with prefix ready for processing while the second has 0x prefix to tell that it's hexadecimal but you can tell that easily by looking at the symbols. You can easily convert them if you want. Just use whatever works best for you :) I still don't know what you are trying to do exactly. Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on September 14, 2020, 03:08:32 PM SORRY! I convert in decimal: 02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9, instead of: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 ::) It's both the same in BASE16. The first one is public key with prefix ready for processing while the second has 0x prefix to tell that it's hexadecimal but you can tell that easily by looking at the symbols. You can easily convert them if you want. Just use whatever works best for you :) I still don't know what you are trying to do exactly. I'm feeling like a SATOSHI NAKAMOTO LOL 8) Title: Re: Private key to public key (TUTORIAL) Post by: bytcoin on September 15, 2020, 05:44:39 PM If the formula is always the same, All public keys will also always be the same! "Where am I wrong? (dx, dy, c, R.x, R.y, Q.x Q.y, P.x, P.y)Can someone explain to me what are this? I think Rx and Ry are the coordinates of the public key, right? ok, I will try to explain as simply as possible because it is true that I myself struggled to understand the system. So it is a question here of adding 2 points (not the same). In this example we use : first point: (all values are in décimal for a better comprehension) X coordinate: 21262057306151627953595685090280431278183829487175876377991189246716355947009 (it is Qx) Y coordinate: 41749993296225487051377864631615517161996906063147759678534462689479575333124 (it is Qy) The Private key for this point is 0000000000000000000000000000000000000000000000000000000000000008 second point to add: X coordinate: 89565891926547004231252920425935692360644145829622209833684329913297188986597 (it is Px) Y coordinate: 12158399299693830322967808612713398636155367887041628176798871954788371653930 (it is Py) The Private key for this point is 0000000000000000000000000000000000000000000000000000000000000002 So to add the 1st point to the second we use the formula : (here modulo is 115792089237316195423570985008687907853269984665640564039457584007908834671663 ) 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 in our example we have dx = (21262057306151627953595685090280431278183829487175876377991189246716355947009 - 89565891926547004231252920425935692360644145829622209833684329913297188986597) % modulo dx = 47488254616920819145913749673032646770809668323194230583764443341328001632075 dy = (41749993296225487051377864631615517161996906063147759678534462689479575333124 - 12158399299693830322967808612713398636155367887041628176798871954788371653930) % modulo dy = 29591593996531656728410056018902118525841538176106131501735590734691203679194 invert of dx = 70279122268919195963430815486314537773961171454828771794853116552210630553734 c = dy * invert(dx) % modulo c = 16132032934385503768504319366562120314980927452732756733183380715276156205226 So the new point (8 + 2) R.x = (c*c - P.x - Q.x) % modulo R.x --> X coordinate of (8+2) = 72488970228380509287422715226575535698893157273063074627791787432852706183111 R.y = (c*(P.x - R.x) - P.y) % modulo R.y --> Y coordinate of (8+2) = 62070622898698443831883535403436258712770888294397026493185421712108624767191 If we check these coordinates, we find that it corresponds to the private key: 000000000000000000000000000000000000000000000000000000000000000a (10) There you go, I hope I was as clear as possible and apologies for my broken English ^^ [/quote] Good explanation ... I understood perfectly Title: Re: Private key to public key (TUTORIAL) Post by: bytcoin on September 15, 2020, 05:47:36 PM That's what I wanted! Could you make private key 3? We must not forget that there are two formulasThe one you used to find the point corresponding to the private key: 2 (or rather 0000000000000000000000000000000000000000000000000000000000000002 to be more precise) it is Duplication of points. You did it in your example with the base point--> 1 + 1 =2 (but that could be another point) To go now with 3 we need to do --> 2 + 1 = 3 (we have now 2 différents points and we can't doubling them) For that you need to use the second formula: modulo = 115792089237316195423570985008687907853269984665640564039457584007908834671663 Px = 89565891926547004231252920425935692360644145829622209833684329913297188986597 (x coordinate point 2) Py = 12158399299693830322967808612713398636155367887041628176798871954788371653930 (y coordinate point 2) Qx = 55066263022277343669578718895168534326250603453777594175500187360389116729240 (x coordinate point 1) not because it is the base point, just because it is the point n°1 Qy = 32670510020758816978083085130507043184471273380659243275938904335757337482424 (y coordinate point 1) dx = (Qx - Px) % modulo --> 34499628904269660561674201530767158034393542375844615658184142552908072257357 dy = (Qy - Py) % modulo --> 95279978516251208768455708490894263304954079172022948940317551626939868843169 c = dy * invert(dx) % modulo --> 23578750110654438173404407907450265080473019639451825850605815020978465167024 Rx = (c*c - Px - Qx) % modulo --> 112711660439710606056748659173929673102114977341539408544630613555209775888121 (x coordinate of point (2+1 =3) Ry = (c*(Px - Rx) - Py) % modulo --> 25583027980570883691656905877401976406448868254816295069919888960541586679410 (y coordinate of point (2+1 =3) Can't explain better Order: 115792089237316195423570985008687907852837564279074904382605163141518161494337 Base Point: (55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424) Modulo: 115792089237316195423570985008687907853269984665640564039457584007908834671663 Private key: 0000000000000000000000000000000000000000000000000000000000000003 Point addition:(2G+1G =3G) Compressed public key; In decimal; Equation: c = (qy – py) / (qx – px) rx = c^2 – px – qx px = 89565891926547004231252920425935692360644145829622209833684329913297188986597 py = 12158399299693830322967808612713398636155367887041628176798871954788371653930 qx = 55066263022277343669578718895168534326250603453777594175500187360389116729240 qy = 32670510020758816978083085130507043184471273380659243275938904335757337482424 c = 32670510020758816978083085130507043184471273380659243275938904335757337482424- 12158399299693830322967808612713398636155367887041628176798871954788371653930= 20512110721064986655115276517793644548315905493617615099140032380968965828494 c = 55066263022277343669578718895168534326250603453777594175500187360389116729240- 89565891926547004231252920425935692360644145829622209833684329913297188986597= 81292460333046534861896783477920749818876442289795948381273441455000762414306 c = 20512110721064986655115276517793644548315905493617615099140032380968965828494/ 81292460333046534861896783477920749818876442289795948381273441455000762414306= 23578750110654438173404407907450265080473019639451825850605815020978465167024 c = 23578750110654438173404407907450265080473019639451825850605815020978465167024 rx = 23578750110654438173404407907450265080473019639451825850605815020978465167024^2 - 89565891926547004231252920425935692360644145829622209833684329913297188986597- 55066263022277343669578718895168534326250603453777594175500187360389116729240 rx = 25759636913902563110438328477658084082469757293658084474899962813078412260632- 34499628904269660561674201530767158034393542375844615658184142552908072257357 rx = 107052097246949097972335111955578833901346199583454032856173404268079174674938 rx hex = 0xecad56ff86123a68f47514b195ab6837ba69c1fbdf0beb6339e6f3caead069fa Now I will try to calculate the private key 0000000000000000000000000000000000000000000000000000000000000005 @ricardosuperx, rx should be DEC 112711660439710606056748659173929673102114977341539408544630613555209775888121 HEX 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9 Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on September 15, 2020, 09:54:14 PM Order: 115792089237316195423570985008687907852837564279074904382605163141518161494337
Modulo: 115792089237316195423570985008687907853269984665640564039457584007908834671663 Private key: 0000000000000000000000000000000000000000000000000000000000000003 Point addition:(2G+1G =3G) Compressed public key; In decimal; Equation: c = (qy – py) / (qx – px) rx = c^2 – px – qx px = 89565891926547004231252920425935692360644145829622209833684329913297188986597 py = 12158399299693830322967808612713398636155367887041628176798871954788371653930 qx = 55066263022277343669578718895168534326250603453777594175500187360389116729240 qy = 32670510020758816978083085130507043184471273380659243275938904335757337482424 c = 32670510020758816978083085130507043184471273380659243275938904335757337482424- 12158399299693830322967808612713398636155367887041628176798871954788371653930= 20512110721064986655115276517793644548315905493617615099140032380968965828494 c = 55066263022277343669578718895168534326250603453777594175500187360389116729240- 89565891926547004231252920425935692360644145829622209833684329913297188986597= 81292460333046534861896783477920749818876442289795948381273441455000762414306 c = 20512110721064986655115276517793644548315905493617615099140032380968965828494/ 81292460333046534861896783477920749818876442289795948381273441455000762414306= 23578750110654438173404407907450265080473019639451825850605815020978465167024 c = 23578750110654438173404407907450265080473019639451825850605815020978465167024 rx = 23578750110654438173404407907450265080473019639451825850605815020978465167024^2 - 89565891926547004231252920425935692360644145829622209833684329913297188986597- 55066263022277343669578718895168534326250603453777594175500187360389116729240 rx = 25759636913902563110438328477658084082469757293658084474899962813078412260632- 34499628904269660561674201530767158034393542375844615658184142552908072257357 rx = 107052097246949097972335111955578833901346199583454032856173404268079174674938 The correct is:112711660439710606056748659173929673102114977341539408544630613555209775888121 What did I do wrong? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on September 15, 2020, 10:32:16 PM -snip- The correct is:112711660439710606056748659173929673102114977341539408544630613555209775888121 What did I do wrong? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? Why do not you examine the messages above? There are two different formulas: one for duplication and another for addition. To be honest your messages are very hard to read. It could be more helpful for you if you can ask the specific question you do not understand or have issues with. Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on September 15, 2020, 10:40:56 PM -snip- The correct is:112711660439710606056748659173929673102114977341539408544630613555209775888121 What did I do wrong? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? Why do not you examine the messages above? There are two different formulas: one for duplication and another for addition. To be honest your messages are very hard to read. It could be more helpful for you if you can ask the specific question you do not understand or have issues with. Duplicate point I already understood That will be my last question. What did I do wrong? Point addition:(2G+1G =3G) Why was my result not: 112711660439710606056748659173929673102114977341539408544630613555209775888121? Order: 115792089237316195423570985008687907852837564279074904382605163141518161494337 Modulo: 115792089237316195423570985008687907853269984665640564039457584007908834671663 Private key: 0000000000000000000000000000000000000000000000000000000000000003 Point addition:(2G+1G =3G) Compressed public key; In decimal; Equation: c = (qy – py) / (qx – px) rx = c^2 – px – qx px = 89565891926547004231252920425935692360644145829622209833684329913297188986597 py = 12158399299693830322967808612713398636155367887041628176798871954788371653930 qx = 55066263022277343669578718895168534326250603453777594175500187360389116729240 qy = 32670510020758816978083085130507043184471273380659243275938904335757337482424 c = 32670510020758816978083085130507043184471273380659243275938904335757337482424- 12158399299693830322967808612713398636155367887041628176798871954788371653930= 20512110721064986655115276517793644548315905493617615099140032380968965828494 c = 55066263022277343669578718895168534326250603453777594175500187360389116729240- 89565891926547004231252920425935692360644145829622209833684329913297188986597= 81292460333046534861896783477920749818876442289795948381273441455000762414306 c = 20512110721064986655115276517793644548315905493617615099140032380968965828494/ 81292460333046534861896783477920749818876442289795948381273441455000762414306= 23578750110654438173404407907450265080473019639451825850605815020978465167024 c = 23578750110654438173404407907450265080473019639451825850605815020978465167024 rx = 23578750110654438173404407907450265080473019639451825850605815020978465167024^2 - 89565891926547004231252920425935692360644145829622209833684329913297188986597- 55066263022277343669578718895168534326250603453777594175500187360389116729240 rx = 25759636913902563110438328477658084082469757293658084474899962813078412260632- 34499628904269660561674201530767158034393542375844615658184142552908072257357 rx = 107052097246949097972335111955578833901346199583454032856173404268079174674938 Correct resultt:112711660439710606056748659173929673102114977341539408544630613555209775888121 Title: Re: Private key to public key (TUTORIAL) Post by: archyone on September 16, 2020, 05:30:48 AM c = (qy – py) / (qx – px)
rx = c^2 – px – qx Wrong formula Use this one --> dx = (Qx - Px) % modulo dy = (Qy - Py) % modulo c = dy * invert(dx) % modulo Rx = (c*c - Px - Qx) % modulo Ry = (c*(Px - Rx) - Py) % modulo Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on September 16, 2020, 11:57:34 AM c = (qy – py) / (qx – px) rx = c^2 – px – qx Wrong formula Use this one --> dx = (Qx - Px) % modulo dy = (Qy - Py) % modulo c = dy * invert(dx) % modulo Rx = (c*c - Px - Qx) % modulo Ry = (c*(Px - Rx) - Py) % modulo Formula is correct. Actually invert(dx) is (qx – px), so c = dy * invert(dx) is the same as c = (qy – py) / (qx – px) Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on September 16, 2020, 12:41:22 PM -snip- rx = 23578750110654438173404407907450265080473019639451825850605815020978465167024^2 - 89565891926547004231252920425935692360644145829622209833684329913297188986597- 55066263022277343669578718895168534326250603453777594175500187360389116729240 rx = 25759636913902563110438328477658084082469757293658084474899962813078412260632- 34499628904269660561674201530767158034393542375844615658184142552908072257357 rx = 107052097246949097972335111955578833901346199583454032856173404268079174674938 Correct resultt:112711660439710606056748659173929673102114977341539408544630613555209775888121 Your calculations of dx, dy and c are correct. However while calculating the rx you made a simple arithmetical mistake - you should deduct step by step, but not make the last deduction first and later deduct the result from the first part. I marked by red the wrong part of your calculation - you changed the sign of px: instead of rx = c^2 – px – qx you calculated rx = c^2 + px – qx (wrong!!) Your calculation should be the following: rx = 23578750110654438173404407907450265080473019639451825850605815020978465167024^2 - 89565891926547004231252920425935692360644145829622209833684329913297188986597- 55066263022277343669578718895168534326250603453777594175500187360389116729240 rx = 25759636913902563110438328477658084082469757293658084474899962813078412260632 - 89565891926547004231252920425935692360644145829622209833684329913297188986597- 55066263022277343669578718895168534326250603453777594175500187360389116729240 rx = 51985834224671754302756393060410299575095596129676438680673216907690057945698- 55066263022277343669578718895168534326250603453777594175500187360389116729240 rx = 112711660439710606056748659173929673102114977341539408544630613555209775888121 PS. You can also calculate in your way, however instead of deducting you should should apply the addition to last 2 decimals deducted from the c*c. This is the possible way as well: rx = c^2 – px – qx = rx = c^2 – (px + qx) Keep in mind that as you combined the last 2 decimals, you should add them first and later deduct from the 1st part}. In general, you mistake is simple math arithmetical. Just be careful with the calculation. Title: Re: Private key to public key (TUTORIAL) Post by: ricardosuperx on September 16, 2020, 07:18:57 PM I would like to thank everyone who helped me understand. Sorry for being boring.
I'm really happy to finally understand how to duplicate points and also calculate addition points The Bitcoin community is amazing! In my opinion, the Bitcoin community has helped Bitcoin to be a success Title: Re: Private key to public key (TUTORIAL) Post by: bigvito19 on September 17, 2020, 01:31:10 PM Does anyone know the correct math and is there a script to do the math for you or do you have to do the math manually?
Title: Re: Private key to public key (TUTORIAL) Post by: MrFreeDragon on September 17, 2020, 07:30:30 PM Does anyone know the correct math and is there a script to do the math for you or do you have to do the math manually? Please find the python script to do the elliptic curve math. It is recommended to use gmpy2 library (it is 50 times faster). However if you do not have installed gmpy2 library, just change the formula for c in functions mul2 and add (you should uncomment the formula for c with self-written modinv function and comment the formula for c with gmpy2 library). How to use this scrpipt: PG is the basis point G (actully the point for private key number 1) mul2 function makes the duplication of the point (i.e. mul2(PG) returns the Point for private key 2 add function performs the addition of 2 different points (i.e. add(mul2(PG),PG) returns the Point for private key 3 in the way 1*2+1 = 3) mulk function multiplies the Point by k number (i.e. you can use it in order to receive the Public point for any private key, for example, for private key 1000 you can calculate the public point in this way: mulk(1000,PG) - multiplies basis point G by 1000). Code: import gmpy2 Title: Re: Private key to public key (TUTORIAL) Post by: BASE16 on September 18, 2020, 10:34:38 AM Code: # Super simple Elliptic Curve Presentation. No imported libraries, wrappers, nothing. For some unknown reason the forum software seems to alter the code inside the code tag so here is the original code on github: https://raw.githubusercontent.com/wobine/blackboard101/master/EllipticCurvesPart4-PrivateKeyToPublicKey.py (https://raw.githubusercontent.com/wobine/blackboard101/master/EllipticCurvesPart4-PrivateKeyToPublicKey.py) |