Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
HABJo12
on 25/03/2025, 12:54:18 UTC
uSE THIS FOR PYTHON import hashlib
import ecdsa
import random
from multiprocessing import Pool, cpu_count, Manager
import queue

# Define constants
TARGET_HASH160 = "e0b8a2baee1b77fc703455f39d51477451fc8cfc".lower()
LOWER_BOUND = int("80000000000000000", 16)
UPPER_BOUND = int("ffFFFFFFFFFFFFFFF", 16)
KEYS_PER_ITERATION = 1_000_000  # Number of keys to generate per iteration

def private_key_to_hash160(private_key_hex):
    """Generate the Hash160 from a private key using compressed public key."""
    private_key_bytes = bytes.fromhex(private_key_hex)
    sk = ecdsa.SigningKey.from_string(private_key_bytes, curve=ecdsa.SECP256k1)
    vk = sk.get_verifying_key()
    public_key = vk.to_string("compressed")
    sha256_hash = hashlib.sha256(public_key).digest()
    ripemd160 = hashlib.new("ripemd160")
    ripemd160.update(sha256_hash)
    hash160 = ripemd160.hexdigest()
    return hash160

def check_key_range(args):
    """Check a set of random private keys and queue their Hash160 values."""
    num_keys, target_hash160, print_queue, lower_bound, upper_bound = args
    for _ in range(num_keys):
        current_int = random.randint(lower_bound, upper_bound)
        private_key_hex = f"{current_int:064x}"
        hash160 = private_key_to_hash160(private_key_hex)
        print_queue.put((private_key_hex, hash160))
        if hash160.lower() == target_hash160:
            return (private_key_hex, hash160)
    return None

def process_iteration(keys_per_iteration, target_hash160, num_processes, print_queue):
    """Process a set of random keys, printing private keys and Hash160 values."""
    keys_per_process = keys_per_iteration // num_processes
    # Adjust for any remainder
    ranges = [
        (
            keys_per_process if i < num_processes - 1 else keys_per_iteration - (keys_per_process * (num_processes - 1)),
            target_hash160,
            print_queue,
            LOWER_BOUND,
            UPPER_BOUND
        )
        for i in range(num_processes)
    ]

    with Pool(processes=num_processes) as pool:
        result = pool.map_async(check_key_range, ranges)
        while True:
            try:
                priv, h160 = print_queue.get(timeout=0.1)
                print(f"Private Key: {priv}, Hash160: {h160}")
            except queue.Empty:
                if result.ready():
                    break
        results = result.get()

    for res in results:
        if res:
            return res
    return None

def main():
    """Main function to search for a matching Hash160 with random key generation."""
    total_attempts = 0
    iteration = 0
    num_processes = cpu_count()
    manager = Manager()
    print_queue = manager.Queue()

    print(f"Searching for Hash160: {TARGET_HASH160}")
    print(f"Range: {LOWER_BOUND:X} to {UPPER_BOUND:X}")
    print(f"Using {num_processes} processes with {KEYS_PER_ITERATION} keys per iteration\n")

    while True:
        iteration += 1
        total_attempts += KEYS_PER_ITERATION

        print(f"Iteration {iteration}:")
        print(f"Generating {KEYS_PER_ITERATION} random keys...")

        result = process_iteration(KEYS_PER_ITERATION, TARGET_HASH160, num_processes, print_queue)

        if result:
            private_key_hex, hash160 = result
            print(f"\nMatch found after {total_attempts} attempts!")
            print(f"Private Key: {private_key_hex}")
            print(f"Hash160: {hash160}")
            with open("found_match.txt", "w") as f:
                f.write(f"Private Key: {private_key_hex}\nHash160: {hash160}")
            break

        print(f"Completed iteration {iteration}. Total attempts: {total_attempts}\n")

if __name__ == "__main__":
    main()             IF YOU ARE SATISFIED MAKE DROP A TIP HERE ON  16qw4VqkxSSfKzguDyVzM68jsWw71yEgP4