Post
Topic
Board Project Development
Re: Try create Private Key Recovery
by
ICYNOTE2023
on 02/08/2023, 12:25:48 UTC
You could use a lib such as multiprocessing (https://docs.python.org/3/library/multiprocessing.html) to run the generate_random_wif function in parallel.

This will most likely improve performance, as you will be running multiple instances of the same function at the same time.

if you wish, please write down the code you mean, so that it runs well. whether the performance can be faster by using the processor as the process?  Smiley

I asked GPT-4 to do this for you.

https://www.talkimg.com/images/2023/08/02/G2iBI.png

This is the answer:
Quote
Sure, I can help you improve the performance of this Python code using the multiprocessing library. Here is an improved version of the code that uses the multiprocessing library to speed up the process of finding the correct WIF:
Code:
import random
from multiprocessing import Pool
from bitcoinlib.keys import Key

def generate_random_wif(wif, target_address):
    alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
    missing_indices = [i for i in range(len(wif)) if wif[i] == '*']
    found = False
    while not found:
        rand_chars = ''.join(random.choice(alphabet) for _ in range(len(missing_indices)))
        test_wif = wif
        for index, char in zip(missing_indices, rand_chars):
            test_wif = test_wif[:index] + char + test_wif[index+1:]
        try:
            key = Key(wif=test_wif)
            address = key.address()
            if address == target_address:
                found = True
                return test_wif, address
            print(f"Scanning WIF: {test_wif}")
        except:
            print(f"Invalid WIF: {test_wif}")

def worker(input_wif, target_address):
    return generate_random_wif(input_wif, target_address)

def main():
    input_wif = input("Enter a WIF string with missing characters (mark with *): ")
    target_address = input("Enter the target Bitcoin address: ")

    if '*' not in input_wif:
        print("Incorrect entry: * sign missing.")
        return

    pool = Pool(processes=4)
    results = pool.starmap(worker, [(input_wif, target_address)]*4)
    pool.close()
    pool.join()

    found_wifs = [result for result in results if result is not None]
    if found_wifs:
        found_wif, found_address = found_wifs[0]
        print("Correct WIF found:", found_wif)
        print("Corresponding Bitcoin address:", found_address)
        with open("found.txt", "w") as file:
            file.write(found_wif)

        with open("found2.txt", "w") as file:
            file.write(f"WIF: {found_wif}\nAddress: {found_address}")

    else:
        print("The correct WIF was not found. try more.")

if __name__ == "__main__":
    main()
This version of the code creates a Pool of worker processes and uses the starmap method to distribute the work of finding the correct WIF across multiple processes. This should significantly speed up the process of finding the correct WIF. You can adjust the number of processes used by changing the processes parameter when creating the Pool. I hope this helps! Let me know if you have any questions or need further assistance.

https://www.talkimg.com/images/2023/08/02/G2Wmc.png

what about multiple imports? like :
Code:
random import
import hashlib
import base58

and I've added the code :
Code:
from multiprocessing import Pool

it seems that an error has occurred which makes the program never stop. I tried with the private key that I took and tried removing the characters to try it.  Lips sealed