Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
Kostelooscoin
on 23/09/2023, 18:19:53 UTC
this python script generates about 144M private keys with the X and Y keys, which takes a long time to generate, so I'd like to know if it would be possible to speed up the process by keeping the calculation method used in the script, even if it's just a matter of generating the private keys while keeping the calculation method?

addressgeneration.py
Code:
from ecdsa import SigningKey, SECP256k1
import sha3
from binascii import unhexlify
import hashlib
from base58 import b58encode
import bech32
from cashaddress import convert
import datetime

def PrivateKeyComputation(p1: int, p2: int, p3: int, base: int, n: int):
    order = (2 ** 6) * 3 * 149 * 631 * p1 * p2 * p3
    prod = p1 * p2 * p3
    g = pow(base, prod, order + 1)
    privateSet = [None] * n

    for i in range(n):
        if i == 0:
            privateSet[0] = hex(g)
        else:
            k = (g * int(privateSet[i - 1], 16)) % (order + 1)
            privateSet[i] = hex(k)

    return privateSet

def CosetPrivateKeyComputation(p1: int, p2: int, p3: int, base: int, n: int):
    print("Coset PrivateKey Computation started at", datetime.datetime.now())
    prod = p1 * p2 * p3
    h = (2 ** 6) * 3 * 149 * 631
    order = h * prod
    g = pow(base, prod, order + 1)
    privateSet = [None] * n * 8

    for i in range(n):
        if i == 0:
            privateSet[0] = hex(g)
        else:
            k = (g * int(privateSet[i - 1], 16)) % (order + 1)
            privateSet[i] = hex(k)

    pows = [h, h*p1, h*p2, h*p3, h*p1*p2, h*p1*p3, h*p2*p3]

    for j in range(len(pows)):
        g = pow(base, pows[j], order + 1)
        for i in range(n):
            value = (g * int(privateSet[i], 16)) % (order + 1)
            privateSet[(j+1)*h+i] = hex(value)
    print("Coset PrivateKey Computation finished at", datetime.datetime.now())
    return privateSet

def CosetKeysFile(n: int, privateSet):
    print("Writing on txt file started at", datetime.datetime.now())
    f = open("secp256k1_keys.txt", "r+")
    f.seek(0)
    f.write('\t\tPrivateKey  \t\t\t\t\t\t\t\t\t\t  PublicKey-x \t\t\t\t\t\t\t\t\t\t   PublicKey-y  \n')

    for i in range(8*n):
        k = int(privateSet[i], 16).to_bytes(32, "big")
        k = SigningKey.from_string(k, curve=SECP256k1)
        K = k.get_verifying_key().to_string()

        f.write(str(i) + ')\t' + privateSet[i] + '\t' + K.hex()[0:64] + '\t' + K.hex()[64:128] + '\n')

    f.truncate()
    f.close()
    print("Writing on txt file finished at", datetime.datetime.now())

def UncompressedPublicKeyComputation(x, y):
    publicKey = '04' + str(x) + str(y)
    return publicKey

def CompressedPublicKeyComputation(x, y):
    if int(y, 16) % 2 == 0:
        publicKey = '02' + str(x)
    else:
        publicKey = '03' + str(x)

    return publicKey

def checksum_computation(string: str) -> hex:
    cs = hashlib.sha256(hashlib.sha256(unhexlify(string)).digest()).hexdigest()
    checksum = cs[:8]
    return checksum

def BitcoinClassicAddressComputation(publicKey):
    public_key_bytes = unhexlify(publicKey)

    sha256 = hashlib.sha256()
    sha256.update(public_key_bytes)
    hash_temp = sha256.digest()

    ripemd160 = hashlib.new('Ripemd160')
    ripemd160.update(hash_temp)
    hash2_temp = ripemd160.hexdigest()

    hash3_temp = '00' + hash2_temp

    checksum = checksum_computation(hash3_temp)

    hash_final = hash3_temp + str(checksum)
    hash_final_bytes = unhexlify(hash_final)
    address = b58encode(hash_final_bytes).decode("utf-8")
    return address

KeysFileGeneration.py
Code:
import AddressGeneration

p1 = 107361793816595537
p2 = 174723607534414371449
p3 = 341948486974166000522343609283189
base = 7
h = (2 ** 6) * 3 * 149 * 631


privateSet = AddressGeneration.CosetPrivateKeyComputation(p1, p2, p3, base, h)
PublicSet = AddressGeneration.CosetKeysFile(h, privateSet)