Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
indoarts
on 20/03/2021, 05:26:58 UTC
@fxsniper

Here is the code I told you I would upload.  It's not the exact one I was looking for but it is based on the same principle.  Easy to change the range you want to search through. I modified my code to search for the RIPEMD of the address I was looking for. Shaves a few milliseconds off versus processing all the way to the address. I created this probably 6 months ago and I am sure it is not the most efficient coding.  Hopefully it gives you some ideas on how to tweak and make exactly what you are wanting.

Code:
#Amateur, very amateur coding by the Wandering Philosopher
#Tested with Python 2.7
import binascii, hashlib, base58, sys, ecdsa, codecs, os, random
import time
import timeit
#Enter the RIPEMD160 of the address you want to search for; make sure it is in LOWERCASE
ripetofind = '3ee4133d991f52fdf6a25c9834e0745ac74248a4'

def compressed_RIPEMD(privkey):
    start_time = timeit.default_timer()
    pvk_to_bytes = codecs.decode (privkey, 'hex')
    
    #Generates the public key
    key = ecdsa.SigningKey.from_string (pvk_to_bytes, curve=ecdsa.SECP256k1).verifying_key
    key_bytes = key.to_string()
    key_hex = codecs.encode(key_bytes, 'hex')

    if(ord(bytearray.fromhex(key_hex[-2:])) % 2 == 0):
        #If the last byte of Y is Even, add '02'
        public_key_compressed = '02' + key_hex[0:64]

        #Making SHA-256 of compressed pubkey and then RIPEMD-160
        public_key_in_bytes = codecs.decode(public_key_compressed, 'hex')
        sha256_public_key_compressed = hashlib.sha256(public_key_in_bytes)
        sha256_public_key_compressed_digest = sha256_public_key_compressed.digest()

        ripemd160 = hashlib.new('ripemd160')
        ripemd160.update(sha256_public_key_compressed_digest)
        ripemd160_digest = ripemd160.digest()
        ripemd160_hex = codecs.encode(ripemd160_digest, 'hex')
        
    else:
        #If the last byte of Y is Odd, add '03'
        public_key_compressed = '03' + key_hex[0:64]

        #Making SHA-256 of compressed pubkey and then RIPEMD-160
        public_key_in_bytes = codecs.decode(public_key_compressed, 'hex')
        sha256_public_key_compressed = hashlib.sha256(public_key_in_bytes)
        sha256_public_key_compressed_digest = sha256_public_key_compressed.digest()

        ripemd160 = hashlib.new('ripemd160')
        ripemd160.update(sha256_public_key_compressed_digest)
        ripemd160_digest = ripemd160.digest()
        ripemd160_hex = codecs.encode(ripemd160_digest, 'hex')
        elapsed = timeit.default_timer() - start_time
        #Prints status and numbers on screen. Comment out both sys.stdout lines below if not wanted and the countall +=1 ; I liked to know it was working/running.
        sys.stdout.write("\r" + "  Key every: " + str(elapsed)[:7] + " seconds " + " Random RIPEMD160s:  " + ripemd160_hex + "   # of Keys: "  + str(countall))
        sys.stdout.flush()
        fwrite = open('KEYSFOUND.txt', 'a')
        if ripemd160_hex == ripetofind:
            fwrite.write('Key: ' + randomprivkey + '  ' + ripemd160_hex + '\n' )

#Always leave countall = 0 below. If you want the program to run unlimited, comment out the countall +=1 down below
countall = 0
while (countall < 100000000000000):
    if __name__== "__main__":
        
        #Enter the range you want to search through below
        low  = 0x8000000000000000
        high = 0xFFFFFFFFFFFFFFFF
        #high = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140
        randomprivkey = hex( random.randrange( low, high ) ).lstrip("0x").rstrip("L").zfill(64)
        countall +=1
        compressed_RIPEMD(randomprivkey)






can we put  additional code like " with open("my_ripemd _key.txt", "r") ? " cause i have tons of Ripemd address here ?
Regards