Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
mabdlmonem
on 13/10/2024, 19:38:07 UTC
Simple program for puzzle 66 below.

If you want to search from a specific private key number both ways up and down, just use it:

Code:
#!/usr/bin/env python3

from hdwallet import HDWallet
from hdwallet.symbols import BTC
from tqdm import tqdm
from tqdm.contrib.concurrent import process_map

hdwallet = HDWallet(symbol=BTC)

p=0x000000000000000000000000000000000000000000000001a838b13505b26867
middle=p*2
mid=1000000

def go(i):
b=hex(i)
b='0'*(66-len(b))+b[2:]
hdwallet.from_private_key(private_key=b)
a=hdwallet.p2pkh_address()
if a=='13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so':
print('private key: 0x'+b+'\a')
exit()

process_map(go, [x for i in range(mid) for x in {middle-i:0,middle+i:0}], max_workers=10, chunksize=10000)

import sys
print('\a',end='',file=sys.stderr)

Here I set p for previous puzzle pvk and double it.
Middle is the variable from where the search will start.

I think your version have some errors, this version work to me:

Code:
#!/usr/bin/env python3

from hdwallet import HDWallet
from hdwallet.symbols import BTC
from tqdm.contrib.concurrent import process_map
import sys
import concurrent.futures

# Initialize HDWallet for BTC
hdwallet = HDWallet(symbol=BTC)

# Define constants
p = 0x000000000000000000000000000000000000000000000001a838b13505b26867
middle = p * 2
mid = 1000000

# Function to process private keys and check addresses
def go(i):
    # Calculate the private key from the iteration index
    private_key = middle - i if i % 2 == 0 else middle + i
    # Convert the private key to a hex string and ensure it's 64 characters
    b = hex(private_key)[2:].zfill(64)
    # Initialize wallet from private key
    hdwallet.from_private_key(private_key=b)
    # Get address
    address = hdwallet.p2pkh_address()
    # Check if the address matches the target
    if address == '13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so':
        print('Private key: 0x' + b + '\a')
        sys.exit()

# Main script execution with multiprocessing guard
if __name__ == "__main__":
    try:
        # Use process_map to parallelize the work
        process_map(go, range(mid), max_workers=10, chunksize=10000)
    except concurrent.futures.process.BrokenProcessPool:
        print("A process in the pool was terminated abruptly.", file=sys.stderr)
    except KeyboardInterrupt:
        print("Process interrupted.", file=sys.stderr)

    # Optional alert on script completion (in stderr)
    print('\a', end='', file=sys.stderr)
It would work only if the private for the next puzzle is even not odd .