Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
lordfrs
on 28/07/2023, 08:51:11 UTC

I keep asking myself how that works but  always get very confused too. If there were an alleged calculator you could prescribe and a little bit of some explanation as to how the addition and subtraction works it'd be very understandable. I even tried to write a code to add and multiply below is the code. still all I got was an awkward result.

"import argparse
import ecdsa
from ecdsa.ellipticcurve import Point

# Function ato perform point addition
def point_addition(point1, point2):
    return point1 + point2

# Function to perform point subtraction
def point_subtraction(point1, point2):
    return point1 - point2

# Function to perform point multiplication
def point_multiplication(point, scalar):
    return scalar * point

# Function to perform point division (using scalar multiplication by the inverse)
def point_division(point, scalar):
    return point_multiplication(point, ecdsa.numbertheory.inverse_mod(scalar, curve.order()))

# Parse command-line arguments
parser = argparse.ArgumentParser(description="Elliptic Curve Point Operations")
parser.add_argument("-p1", dest="public_key1", type=str, help="Public key 1 (in hexadecimal)")
parser.add_argument("-p2", dest="public_key2", type=str, help="Public key 2 (in hexadecimal)")
parser.add_argument("operation", choices=["+", "-", "*", "/"], help="Operation to perform (+ for add, - for subtract, * for multiply, / for divide)")

args = parser.parse_args()

# Define the elliptic curve parameters (SECP256k1 in Bitcoin)
curve = ecdsa.SECP256k1

# Parse the public keys from the command-line arguments
public_key1 = ecdsa.VerifyingKey.from_string(bytes.fromhex(args.public_key1), curve=curve).pubkey.point
public_key2 = ecdsa.VerifyingKey.from_string(bytes.fromhex(args.public_key2), curve=curve).pubkey.point

# Perform the specified operation on the public keys
if args.operation == "+":
    result_point = point_addition(public_key1, public_key2)
elif args.operation == "-":
    result_point = point_subtraction(public_key1, public_key2)
elif args.operation == "*":
    scalar = int(input("Enter the scalar value (private key): "), 16)
    result_point = point_multiplication(public_key1, scalar)
elif args.operation == "/":
    scalar = int(input("Enter the scalar value (private key): "), 16)
    result_point = point_division(public_key1, scalar)

# Print the coordinates of the result point
result_x, result_y = ecdsa.util.number_to_string(result_point.x(), curve.order), ecdsa.util.number_to_string(result_point.y(), curve.order)
print("Result Point (x, y):", result_x.hex(), ",", result_y.hex())" result was awkward but anyway,

how do we go about the addition and subtraction, division and multiplication and how do we make sense off of the result from this process??
what tools are required?
Calculators and procedures involved. I'm down to learn too
Code:
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 # This defines the curve. y^2 = x^3 + Acurve * x + Bcurve
Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424

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 int(lm % n)

def ECadd(xp,yp,xq,yq): # Not true addition, invented for EC. It adds Point-P with Point-Q.
    m = ((yq-yp) * mod_inverse(xq-xp,Pcurve)) % Pcurve
    xr = (m*m-xp-xq) % Pcurve
    yr = (m*(xp-xr)-yp) % Pcurve
    return (xr,yr)

def ECdouble(xp,yp): # EC point doubling,  invented for EC. It doubles Point-P.
    LamNumer = 3*xp*xp+Acurve
    LamDenom = 2*yp
    Lam = (LamNumer * mod_inverse(LamDenom,Pcurve)) % Pcurve
    xr = (Lam*Lam-2*xp) % Pcurve
    yr = (Lam*(xp-xr)-yp) % Pcurve
    return (xr,yr)

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


You can understand how it works by looking at the code.