def point_addition(p, q, a, p_curve):
if p == "infinity":
return q
if q == "infinity":
return p
x_p, y_p = p
x_q, y_q = q
if p != q:
m = ((y_q - y_p) * pow(x_q - x_p, -1, p_curve)) % p_curve
else:
m = ((3 * x_p**2 + a) * pow(2 * y_p, -1, p_curve)) % p_curve
x_r = (m**2 - x_p - x_q) % p_curve
y_r = (m * (x_p - x_r) - y_p) % p_curve
return (x_r, y_r)
# Elliptic curve parameters
p_curve = 2**256 - 2**32 - 2**9 - 2**8 - 2**7 - 2**6 - 2**4 - 1
a_curve = 0
g_basepoint = (
55066263022277343669578718895168534326250603453777594175500187360389116729240,
32670510020758816978083085130507043184471273380659243275938904335757337482424
)
# Alice's private and public keys
alice_private_key = 17436825491055586112755527818298542034755947930418580382030036978914692463183
alice_public_key = (
105679268965026450260338478364512614840272341529552480851333141374575362812020,
16626610969520910407950657067133267950619549449019363437330088722436240164467
)
# Bob's private and public keys
bob_private_key = 32291818723468099298317452759803795679231875044644200373977689553806184529332
bob_public_key = (
91972152888645730114115627070016955368567223430226022010551427574648772204461,
38446745167120461740412855329188667802416705205856357237503216472671667494148
)
# Calculate (Alice Private + Bob Private) mod p
combined_private_key = (alice_private_key + bob_private_key) % p_curve
# Calculate combined public key
combined_public_key = "infinity"
for i in range(combined_private_key.bit_length()):
if (combined_private_key >> i) & 1:
combined_public_key = point_addition(combined_public_key, g_basepoint, a_curve, p_curve)
print("(Alice Private + Bob Private) * G:", combined_public_key)
print("Alice Public + Bob Public:", point_addition(alice_public_key, bob_public_key, a_curve, p_curve))
Result:
(Alice Private + Bob Private) * G: (42781960159024299958163639356878453190501432691827926213851649420102986506453, 26209845635735715128050436215405957538148584136159453271268754283021438363749)
Alice Public + Bob Public: (101985652621362431772155823262934243650512147323486167826619770748482854554391, 55338466074231142921426831718703469030196983642662166495910251269532062902125)
This is off-topic and not directly related to brute-forcing Bitcoin (BTC).
The focus here is on brute-forcing (trial-and-error guessing) BTC puzzles.
And this code is demonstration of elliptic curve cryptography operations (a combined public key from the sum of two private keys)
rather than an attempt to crack or exploit BTC.
There doesn't appear to be any straightforward way to solve the presented challenge without resorting to years of brute force.