Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
bit_mind
on 24/12/2024, 22:00:54 UTC
How long do you think the hash 160 can break?
How long can it take?


Code:
import hashlib
import time
from itertools import product
import string

def ripemd160(data):
    """
    Compute the RIPEMD-160 hash of the given data.
    """
    h = hashlib.new('ripemd160')
    h.update(data.encode('utf-8'))
    return h.hexdigest()

def brute_force_ripemd160(target_hash, max_length=5):
    """
    Simulate brute-forcing a RIPEMD-160 hash.
    Test all combinations of characters up to a given length.
    """
    characters = string.ascii_letters + string.digits
    start_time = time.time()
    attempt_count = 0  # Track number of attempts
   
    print(f"Brute-forcing RIPEMD-160 hash: {target_hash}")
    print(f"Using characters: {characters}")
   
    # Brute-force attempt
    for length in range(1, max_length + 1):
        print(f"\nTesting all combinations of length: {length}")
        for attempt in product(characters, repeat=length):
            attempt_count += 1
            guess = ''.join(attempt)
            guess_hash = ripemd160(guess)
           
            # Show progress every 100,000 attempts
            if attempt_count % 100000 == 0:
                elapsed_time = time.time() - start_time
                print(f"Attempts: {attempt_count:,} | Time elapsed: {elapsed_time:.2f} seconds")
           
            if guess_hash.upper() == target_hash.upper():
                elapsed_time = time.time() - start_time
                print(f"\nMatch found: {guess}")
                print(f"Attempts: {attempt_count:,}")
                print(f"Time taken: {elapsed_time:.2f} seconds")
                return guess
   
    elapsed_time = time.time() - start_time
    print(f"\nNo match found within {max_length}-character keyspace.")
    print(f"Total attempts: {attempt_count:,}")
    print(f"Time taken: {elapsed_time:.2f} seconds")
    return None

target_hash = "1234567890123456789012345678912345678..."  # Replace with your hash
print(f"Target Hash: {target_hash}")

# Run the brute-force simulation
brute_force_ripemd160(target_hash, max_length=5)