Title: Try create Private Key Recovery Post by: ICYNOTE2023 on August 01, 2023, 02:33:01 PM Hi Guys,,,
I want to try to make a program in python to find or restore a lost private key. The program's goal is also to search for missing characters. Any input, suggestions will be greatly appreciated. If there are deficiencies, please correct them so that they become better. Code: import random I want to ask the experts here, how can this program run even faster. Thank's ;) Title: Re: Try create Private Key Recovery Post by: bitmover on August 01, 2023, 06:32:13 PM 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. Title: Re: Try create Private Key Recovery Post by: ICYNOTE2023 on August 02, 2023, 03:58:11 AM 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? :) Title: Re: Try create Private Key Recovery Post by: pooya87 on August 02, 2023, 05:02:06 AM When you want to write a recovery code (ie. a computation heavy code needing to be heavily optimized) you shouldn't go through the simple route writing a "normal" code like what you'd write for a normal function that encodes/decodes Base58 keys. Instead you should find the bottlenecks in your code and try to go around them by finding alternative computation route that perform faster.
I'm not a python expert but for example in your code when you are replacing * with random chars and then convert it to a key in this line: Code: key = Key(wif=test_wif) Changing that code and doing the conversion from base58 in your own code would significantly improve your speed. Of course when optimizing you must always perform benchmarks on your code and the changes you make so that you don't make it slower. And you should add tests so that you don't introduce bugs. Title: Re: Try create Private Key Recovery Post by: ICYNOTE2023 on August 02, 2023, 05:58:27 AM When you want to write a recovery code (ie. a computation heavy code needing to be heavily optimized) you shouldn't go through the simple route writing a "normal" code like what you'd write for a normal function that encodes/decodes Base58 keys. Instead you should find the bottlenecks in your code and try to go around them by finding alternative computation route that perform faster. I'm not a python expert but for example in your code when you are replacing * with random chars and then convert it to a key in this line: Code: key = Key(wif=test_wif) Changing that code and doing the conversion from base58 in your own code would significantly improve your speed. Of course when optimizing you must always perform benchmarks on your code and the changes you make so that you don't make it slower. And you should add tests so that you don't introduce bugs. Sorry, I'm a bit confused by your statement. please help by writing where should I add or even replace the code in my code above? :) Title: Re: Try create Private Key Recovery Post by: ICYNOTE2023 on August 02, 2023, 10:00:43 AM First of all, using print frequently would slow down your Python script. 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. With that library, OP probably have to modify his generate_random_wif function a bit where each process check different possible range/combination. kindly ask, where should i add. The point is this tool can be used to recover lost characters. :) Title: Re: Try create Private Key Recovery Post by: bitmover on August 02, 2023, 11:44:01 AM 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? :) 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 Title: Re: Try create Private Key Recovery Post by: ICYNOTE2023 on August 02, 2023, 12:15:59 PM 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? :) 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 just adding in the import section, does this include modules? do we have to install a new module? Title: Re: Try create Private Key Recovery Post by: ICYNOTE2023 on August 02, 2023, 12:25:48 PM 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? :) 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 https://www.talkimg.com/images/2023/08/02/G2Wmc.png what about multiple imports? like : Code: random import 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. :-X Title: Re: Try create Private Key Recovery Post by: pooya87 on August 02, 2023, 01:14:34 PM Sorry, I'm a bit confused by your statement. please help by writing where should I add or even replace the code in my code above? :) Start by looking at the existing projects on github that are already doing this (recovering WIF with missing characters). You'll get a good idea.As for what I meant, I'll give you an example. Instead of using the line I mentioned above (key = Key(wif=test_wif)) you'd use these 4 lines (https://github.com/1200wd/bitcoinlib/blob/38f8690294c4cb4644bea7ba6098222ba995844f/bitcoinlib/keys.py#L859-L862) and under the if branch instead of throwing an exception you'd just skip when the checksum is invalid. And in the else branch (you add) you perform the conversion to address and the rest of the checks. Title: Re: Try create Private Key Recovery Post by: ICYNOTE2023 on August 04, 2023, 12:27:16 PM Sorry, I'm a bit confused by your statement. please help by writing where should I add or even replace the code in my code above? :) Start by looking at the existing projects on github that are already doing this (recovering WIF with missing characters). You'll get a good idea.As for what I meant, I'll give you an example. Instead of using the line I mentioned above (key = Key(wif=test_wif)) you'd use these 4 lines (https://github.com/1200wd/bitcoinlib/blob/38f8690294c4cb4644bea7ba6098222ba995844f/bitcoinlib/keys.py#L859-L862) and under the if branch instead of throwing an exception you'd just skip when the checksum is invalid. And in the else branch (you add) you perform the conversion to address and the rest of the checks. Sorry,,, can you replace the code above? because I also confused where put your code. :) |