Pages:
Author

Topic: OFF TOPIC (Read 1640 times)

member
Activity: 180
Merit: 38
September 18, 2020, 05:34:38 AM
#51
Code:
# Super simple Elliptic Curve Presentation. No imported libraries, wrappers, nothing.
# For educational purposes only. Remember to use Python 2.7.6 or lower. You'll need to make changes for Python 3.

# Below are the public specs for Bitcoin's curve - the secp256k1

Pcurve = 2**256 - 2**32 - 2**9 - 2**8 - 2**7 - 2**6 - 2**4 -1 # The proven prime
N=0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 # Number of points in the field
Acurve = 0; Bcurve = 7 # These two defines the elliptic curve. y^2 = x^3 + Acurve * x + Bcurve
Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424
GPoint = (Gx,Gy) # This is our generator point. Trillions of dif ones possible

#Individual Transaction/Personal Information
privKey = 0xA0DC65FFCA799873CBEA0AC274015B9526505DAAAED385155425F7337704883E #replace with any private key

def modinv(a,n=Pcurve): #Extended Euclidean Algorithm/'division' in elliptic curves
    lm, hm = 1,0
    low, high = a%n,n
    while low > 1:
        ratio = high/low
        nm, new = hm-lm*ratio, high-low*ratio
        lm, low, hm, high = nm, new, lm, low
    return lm % n

def ECadd(a,b): # Not true addition, invented for EC. Could have been called anything.
    LamAdd = ((b[1]-a[1]) * modinv(b[0]-a[0],Pcurve)) % Pcurve
    x = (LamAdd*LamAdd-a[0]-b[0]) % Pcurve
    y = (LamAdd*(a[0]-x)-a[1]) % Pcurve
    return (x,y)

def ECdouble(a): # This is called point doubling, also invented for EC.
    Lam = ((3*a[0]*a[0]+Acurve) * modinv((2*a[1]),Pcurve)) % Pcurve
    x = (Lam*Lam-2*a[0]) % Pcurve
    y = (Lam*(a[0]-x)-a[1]) % Pcurve
    return (x,y)

def EccMultiply(GenPoint,ScalarHex): #Double & add. Not true multiplication
    if ScalarHex == 0 or ScalarHex >= N: raise Exception("Invalid Scalar/Private Key")
    ScalarBin = str(bin(ScalarHex))[2:]
    Q=GenPoint
    for i in range (1, len(ScalarBin)): # This is invented EC multiplication.
        Q=ECdouble(Q); # print "DUB", Q[0]; print
        if ScalarBin[i] == "1":
            Q=ECadd(Q,GenPoint); # print "ADD", Q[0]; print
    return (Q)

print; print "******* Public Key Generation *********";
print
PublicKey = EccMultiply(GPoint,privKey)
print "the private key:";
print privKey; print
print "the uncompressed public key (not address):";
print PublicKey; print
print "the uncompressed public key (HEX):";
print "04" + "%064x" % PublicKey[0] + "%064x" % PublicKey[1];
print;
print "the official Public Key - compressed:";
if PublicKey[1] % 2 == 1: # If the Y value for the Public Key is odd.
    print "03"+str(hex(PublicKey[0])[2:-1]).zfill(64)
else: # Or else, if the Y value is even.
    print "02"+str(hex(PublicKey[0])[2:-1]).zfill(64)

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
sr. member
Activity: 443
Merit: 350
September 17, 2020, 02:30:30 PM
#50
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

modulo = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
order  = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
Gy = 0X483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8

class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

PG = Point(Gx,Gy)
Z = Point(0,0) # zero-point, infinite in real x,y - plane

# return (g, x, y) a*x + b*y = gcd(x, y)
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, x, y = egcd(b % a, a)
        return (g, y - (b // a) * x, x)

def modinv(m, n = modulo):
    while m < 0:
        m += n
    g, x, _ = egcd(m, n)
    if g == 1:
        return x % n

    else: print (' no inverse exist')

def mul2(Pmul2, p = modulo):
    R = Point(0,0)
    #c = 3*Pmul2.x*Pmul2.x*modinv(2*Pmul2.y, p) % p
    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

def add(Padd, Q, p = modulo):
    if Padd.x == Padd.y == 0: return Q
    if Q.x == Q.y == 0: return Padd
    if Padd == Q: return mul2(Q)
    R = Point()
    dx = (Q.x - Padd.x) % p
    dy = (Q.y - Padd.y) % p
    c = dy * gmpy2.invert(dx, p) % p     
    #c = dy * modinv(dx, p) % p
    R.x = (c*c - Padd.x - Q.x) % p
    R.y = (c*(Padd.x - R.x) - Padd.y) % p
    return R # 6 sub, 3 mul, 1 inv

def mulk(k, Pmulk, p = modulo):
    if k == 0: return Z
    if k == 1: return Pmulk
    if (k % 2 == 0): return mulk(k//2, mul2(Pmulk, p), p)
    return add(Pmulk, mulk((k-1)//2, mul2(Pmulk, p), p), p)
full member
Activity: 706
Merit: 111
September 17, 2020, 08:31:10 AM
#49
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?
member
Activity: 109
Merit: 13
A positive attitude changes everything *_*
September 16, 2020, 02:18:57 PM
#48
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
sr. member
Activity: 443
Merit: 350
September 16, 2020, 07:41:22 AM
#47
-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.
sr. member
Activity: 443
Merit: 350
September 16, 2020, 06:57:34 AM
#46
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)
newbie
Activity: 25
Merit: 1
September 16, 2020, 12:30:48 AM
#45
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

member
Activity: 109
Merit: 13
A positive attitude changes everything *_*
September 15, 2020, 05:40:56 PM
#44
-snip-
The correct is:112711660439710606056748659173929673102114977341539408544630613555209775888121

What did I do wrong?
HuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuh


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.
SORRY! My English is bad and I'm not good at math or programming.
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
sr. member
Activity: 443
Merit: 350
September 15, 2020, 05:32:16 PM
#43
-snip-
The correct is:112711660439710606056748659173929673102114977341539408544630613555209775888121

What did I do wrong?
HuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuh

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.
member
Activity: 109
Merit: 13
A positive attitude changes everything *_*
September 15, 2020, 04:54:14 PM
#42
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?
HuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuhHuh
member
Activity: 211
Merit: 20
$$$$$$$$$$$$$$$$$$$$$$$$$
September 15, 2020, 12:47:36 PM
#41
That's what I wanted! Could you make private key 3?
We must not forget that there are two formulas
The 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
member
Activity: 211
Merit: 20
$$$$$$$$$$$$$$$$$$$$$$$$$
September 15, 2020, 12:44:39 PM
#40
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
member
Activity: 109
Merit: 13
A positive attitude changes everything *_*
September 14, 2020, 10:08:32 AM
#39


SORRY! I convert in decimal: 02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9,
instead of: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9
 Roll Eyes

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  Smiley

I still don't know what you are trying to do exactly.
I'm just trying to learn the math behind bitcoin! I was always curious to understand how public keys are created and how Bitcoin works etc ... I was able to understand how to double points and now I understand  addition points
I'm feeling like a SATOSHI NAKAMOTO LOL Cool
member
Activity: 180
Merit: 38
September 14, 2020, 09:56:53 AM
#38


SORRY! I convert in decimal: 02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9,
instead of: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9
 Roll Eyes

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  Smiley

I still don't know what you are trying to do exactly.
member
Activity: 109
Merit: 13
A positive attitude changes everything *_*
September 14, 2020, 09:43:58 AM
#37
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
Corrected, thanks!
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  Smiley




SORRY! I convert in decimal: 02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9,
instead of: 0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9
 Roll Eyes
Now I will try to calculate the private key 0000000000000000000000000000000000000000000000000000000000000005
member
Activity: 180
Merit: 38
September 14, 2020, 09:19:04 AM
#36
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
Corrected, thanks!
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  Smiley


member
Activity: 109
Merit: 13
A positive attitude changes everything *_*
September 14, 2020, 08:56:03 AM
#35
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
Corrected, thanks!
 
X:  0xf9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9
Y:  0x388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672

EDITED:THIS IS THE KEY PUBLIC OF THE PRIVATE KEY
0000000000000000000000000000000000000000000000000000000000000003
member
Activity: 180
Merit: 38
September 14, 2020, 08:18:48 AM
#34
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
member
Activity: 109
Merit: 13
A positive attitude changes everything *_*
September 14, 2020, 07:54:27 AM
#33
That's what I wanted! Could you make private key 3?
We must not forget that there are two formulas
The 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
sr. member
Activity: 443
Merit: 350
September 13, 2020, 06:51:30 PM
#32
-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
(55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424)
>>> P2=mul2(PG)
>>> int(P2.x), int(P2.y)
(89565891926547004231252920425935692360644145829622209833684329913297188986597, 12158399299693830322967808612713398636155367887041628176798871954788371653930)
>>> P3=add(P2,PG)
>>> int(P3.x), int(P3.y)
(112711660439710606056748659173929673102114977341539408544630613555209775888121, 25583027980570883691656905877401976406448868254816295069919888960541586679410)
Pages:
Jump to: