Bitcoin Forum
June 15, 2024, 06:00:12 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 2 [3]  All
  Print  
Author Topic: OFF TOPIC  (Read 1581 times)
bytcoin
Member
**
Offline Offline

Activity: 211
Merit: 20

$$$$$$$$$$$$$$$$$$$$$$$$$


View Profile
September 15, 2020, 05: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
ricardosuperx (OP)
Member
**
Offline Offline

Activity: 109
Merit: 13

A positive attitude changes everything *_*


View Profile
September 15, 2020, 09: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

MrFreeDragon
Sr. Member
****
Offline Offline

Activity: 443
Merit: 350


View Profile
September 15, 2020, 10: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.

ricardosuperx (OP)
Member
**
Offline Offline

Activity: 109
Merit: 13

A positive attitude changes everything *_*


View Profile
September 15, 2020, 10:40:56 PM
Last edit: September 15, 2020, 11:34:52 PM by ricardosuperx
 #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

archyone
Newbie
*
Offline Offline

Activity: 25
Merit: 1


View Profile
September 16, 2020, 05: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

MrFreeDragon
Sr. Member
****
Offline Offline

Activity: 443
Merit: 350


View Profile
September 16, 2020, 11: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)

MrFreeDragon
Sr. Member
****
Offline Offline

Activity: 443
Merit: 350


View Profile
September 16, 2020, 12:41:22 PM
 #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.

ricardosuperx (OP)
Member
**
Offline Offline

Activity: 109
Merit: 13

A positive attitude changes everything *_*


View Profile
September 16, 2020, 07: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

bigvito19
Full Member
***
Offline Offline

Activity: 706
Merit: 111


View Profile
September 17, 2020, 01:31:10 PM
 #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?
MrFreeDragon
Sr. Member
****
Offline Offline

Activity: 443
Merit: 350


View Profile
September 17, 2020, 07: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)

BASE16
Member
**
Offline Offline

Activity: 180
Merit: 38


View Profile
September 18, 2020, 10:34:38 AM
Last edit: September 18, 2020, 02:32:52 PM by BASE16
 #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
Pages: « 1 2 [3]  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!