So, let me be clear.
According to this process from here, you say that someone is decoding the public key and extract the private key? So if they do reverse engineering of this process from this script, this means that they can decode almost any public key and get the private key very easy, no?
from ecdsa.ellipticcurve import CurveFp, Point
import time
# --- secp256k1 Parameters ---
p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
a = 0
b = 7
# Generator point G
Gx = int("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16)
Gy = int("483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 16)
# Create curve and generator point
curve = CurveFp(p, a, b)
G = Point(curve, Gx, Gy)
# --- Compressed Public Key (replace with your own) ---
compressed_pubkey = "02545d2611c823a396ef6712ce0f712f09b9b4f3135e3e0aa3230fb9b6d08d1e16"
# --- Helper: Modular square root (for p % 4 == 3) ---
def modular_sqrt(a, p):
if pow(a, (p - 1) // 2, p) != 1:
return None
return pow(a, (p + 1) // 4, p)
# --- Decompress compressed public key ---
def decompress_pubkey(comp):
prefix = int(comp[:2], 16)
x = int(comp[2:], 16)
y_sq = (pow(x, 3, p) + a * x + b) % p
y = modular_sqrt(y_sq, p)
if y is None:
raise ValueError("Invalid compressed public key")
# Adjust sign of y based on prefix
if (prefix == 0x02 and y % 2 != 0) or (prefix == 0x03 and y % 2 == 0):
y = (-y) % p
return Point(curve, x, y)
# --- Brute-force small private key ---
def find_private_key(G, P, max_d=1000000000):
print(f"🔍 Brute-forcing d such that P = d * G (max {max_d})...")
start = time.time()
point = None
for d in range(1, max_d):
point = d * G
if point == P:
end = time.time()
print(f"✅ Match found in {end - start:.2f} seconds!")
return d
if d % 100000 == 0:
print(f"Checked {d} keys...")
print("❌ No match found in given range.")
return None
# --- Main Execution ---
try:
P = decompress_pubkey(compressed_pubkey)
print("🔓 Decompressed Public Key:")
print("Px =", hex(P.x()))
print("Py =", hex(P.y()))
# Try to recover private key
private_key = find_private_key(G, P, max_d=1000000)
if private_key:
print("\n🔐 Private Key Found!")
print("Private Key (decimal):", private_key)
print("Private Key (hex):", hex(private_key))
else:
print("\n❌ Private key not found in the given range.")
except Exception as e:
print("Error:", e)