Title: Python HEX generator Range based Post by: Marshal TITO on April 26, 2021, 10:02:45 AM Hi.
is there a python script somebody know, that can genearate HEX numbers in a given range and output it in a txt file ? THX Title: Re: Python HEX generator Range based Post by: HeRetiK on April 26, 2021, 10:25:08 AM What do you mean exactly?
(a) Random hex numbers within a range, (b) all hex numbers within a range, (c) convert a list of decimal numbers to hex numbers or (d) something else entirely? Also, what are you trying to do? Title: Re: Python HEX generator Range based Post by: ABCbits on April 26, 2021, 11:17:25 AM Since you're not being specific, i made something very simple
Code: start = 0x0 The output should look like this Code: 0x0 But as @HeRetiK said, what do you want to accomplish? It's possible you fell to XY problem. Title: Re: Python HEX generator Range based Post by: NotATether on April 26, 2021, 11:17:44 AM What do you mean exactly? (a) Random hex numbers within a range, (b) all hex numbers within a range, (c) convert a list of decimal numbers to hex numbers or (d) something else entirely? Also, what are you trying to do? I'm going to assume that he's trying to generate random hex private keys (because otherwise what does this have to do with bitcoin or cryptography?), so the first thing I'd look for is a secure random number generator, so nothing that random exports. secrets (https://docs.python.org/3/library/secrets.html) is a much better module for this purpose and it has a function called randbits(n) that generates an n-bit random number. In this case, 256 bits are needed, and the result can easily be converted to hex using the hex() function. Full code is just from secrets import randbits hex(randbits(256)) Plain old insecure random numbers can always be generated using hex(random.randrange(start, end)) And of course we can always iterate through a range using for a in hex(range(start, end)): Hi, you can use secrets library.. "pip install secrets" You don't need to install it from pip (it isn't there anyway) because it's bundled with Python since 3.6. Title: Re: Python HEX generator Range based Post by: archyone on April 26, 2021, 11:20:08 AM Hi, you can use secrets library.. "pip install secrets"
Code: import secrets et voila ! ;) edit: it is for random génération, don't know if you want a linear génération ? in this case ETFbitcoin example is the good one ^^ Title: Re: Python HEX generator Range based Post by: Marshal TITO on April 26, 2021, 11:26:09 AM I would like to have a Script like this
https://github.com/saracen/bitcoin-all-key-generator (https://github.com/saracen/bitcoin-all-key-generator) in python, because thats what i have installed 2.7 and 3.xx. Where i can set the starting point for example start with 0000000000000000000000000000000000000000000000000000251462abc584 and output to a txt file. @NotATether, you told me in pm the PK, with missing letters, is in a range of xxx and xxxxx so maybe i can search it this way. Title: Re: Python HEX generator Range based Post by: bitmover on April 26, 2021, 11:55:03 AM I would like to have a Script like this https://github.com/saracen/bitcoin-all-key-generator (https://github.com/saracen/bitcoin-all-key-generator) in python, because thats what i have installed 2.7 and 3.xx. Where i can set the starting point for example start with 0000000000000000000000000000000000000000000000000000251462abc584 and output to a txt file. You want a random 256-bit number like this: Code: import random this will output a 256-bit number, just like any bitcoin private key. I ran this here and it returned: Code: 92190443112138794064351826137983695759100025828546020995296739378362186540927 To create a file you can use ETFBitcoin solution, like this: Code: import random https://en.bitcoin.it/wiki/Private_key#:~:text=In%20Bitcoin%2C%20a%20private%20key,range%200%2D9%20or%20A%2DF. Quote In Bitcoin, a private key is a 256-bit number, which can be represented one of several ways. Here is a private key in hexadecimal - 256 bits in hexadecimal is 32 bytes, or 64 characters in the range 0-9 or A-F. E9873D79C6D87DC0FB6A5778633389_SAMPLE_PRIVATE_KEY_DO_NOT_IMPORT_F4453213303DA61 F20BD67FC233AA33262 Edit: For security purposes, using secrets lib like NotATether suggested is better. Title: Re: Python HEX generator Range based Post by: Marshal TITO on April 26, 2021, 12:22:28 PM It look all great, and thx for all that wanna help.
Now how can i start with a from me given HEX number for example 0000000000000000000000000000000000000000000000000000251462abc584, and lets say, generate linear the next 10k HEX numbers or 20k. Title: Re: Python HEX generator Range based Post by: bitmover on April 26, 2021, 01:27:16 PM It look all great, and thx for all that wanna help. Now how can i start with a from me given HEX number for example 0000000000000000000000000000000000000000000000000000251462abc584, and lets say, generate linear the next 10k HEX numbers or 20k. I managed to do it: Code: import secrets You can change stop (10000) and start for whatever number you like To add to txt Code: import secrets Title: Re: Python HEX generator Range based Post by: Marshal TITO on April 26, 2021, 02:16:55 PM It look all great, and thx for all that wanna help. Now how can i start with a from me given HEX number for example 0000000000000000000000000000000000000000000000000000251462abc584, and lets say, generate linear the next 10k HEX numbers or 20k. I managed to do it: Code: import secrets You can change stop (10000) and start for whatever number you like To add to txt Code: import secrets When i do this code, it gives me 00000000000000000000000000000000000000000000000000x251462abe24aL that means i have to take 00000000000000000000000000000000000000000000000000x251462abe24a, because the L is only a python "Mistake" ! But it is possible, to write all the hex, in the txt file, every in one line ... so that on 10k it generate 10k lines linear to the start HEX number ?! Title: Re: Python HEX generator Range based Post by: bitmover on April 26, 2021, 02:52:40 PM When i do this code, it gives me 00000000000000000000000000000000000000000000000000x251462abe24aL that means i have to take 00000000000000000000000000000000000000000000000000x251462abe24a, because the L is only a python "Mistake" ! I was not able to reproduce this "bug" here. Quote But it is possible, to write all the hex, in the txt file, every in one line ... so that on 10k it generate 10k lines linear to the start HEX number ?! You don't want to generate a random number. You want just to count in hex? That's even easier: Code: path = './file.txt' I made a small change in the code, added .replace("x","0") so you do not see the x again, looks more like a bitcoin private key. Looks like you are trying to find private key with balance... This won't work for that. This is why: If your private keys are properly generated, they cannot be guessed or brute forced. Take a look at this infographic so you have an idea about the size of combinations: http://miguelmoreno.net/wp-content/uploads/2013/05/fYFBsqp.jpg source: https://www.reddit.com/r/Bitcoin/comments/1ohwvu/bitcoin_your_money_is_secured_by_the_laws_of_the/ Title: Re: Python HEX generator Range based Post by: BrewMaster on April 26, 2021, 04:11:57 PM Looks like you are trying to find private key with balance... This won't work for that. This is why: base on post history of the starter i believe he is trying to recover his own private key that is damaged and is missing a part of it. that is probably why the range looks like this. although if starter was more clear about what he is trying to do he would also get better help. Title: Re: Python HEX generator Range based Post by: Marshal TITO on April 26, 2021, 04:31:55 PM I know, Bitcoin is the perpetuum mobile, of the cryptohack.
But ... now comes the BUT, since i search the lost letters from my PK ( see this post https://bitcointalk.org/index.php?topic=5331951.0 (https://bitcointalk.org/index.php?topic=5331951.0) ), i read and read, try to understand and try to learn. Maybe because i am a older generation ( C64 ... Amiga 500 ), the CONTRA REGULE thinking ( against normal rules ), is breaking through. Why all brute force tryings go one way. Nobody thinks CONTRA REGULE, but this is another post, what i will open soon. My biggest problem is that i cant write a script ::) ::) ::) ::) Big thanks for help, solving this problem here. Title: Re: Python HEX generator Range based Post by: WanderingPhilospher on April 26, 2021, 04:34:31 PM It look all great, and thx for all that wanna help. Now how can i start with a from me given HEX number for example 0000000000000000000000000000000000000000000000000000251462abc584, and lets say, generate linear the next 10k HEX numbers or 20k. I managed to do it: Code: import secrets You can change stop (10000) and start for whatever number you like To add to txt Code: import secrets When i do this code, it gives me 00000000000000000000000000000000000000000000000000x251462abe24aL that means i have to take 00000000000000000000000000000000000000000000000000x251462abe24a, because the L is only a python "Mistake" ! But it is possible, to write all the hex, in the txt file, every in one line ... so that on 10k it generate 10k lines linear to the start HEX number ?! Here is how I would do it: Code: arq1 = open('sequentialkeys.txt', 'a') Results file looks like this: Code: 0000000000000000000000000000000000000000000000000000251462abc585 Title: Re: Python HEX generator Range based Post by: Marshal TITO on April 26, 2021, 04:43:09 PM Perfect thank you !
Title: Re: Python HEX generator Range based Post by: NotATether on April 26, 2021, 06:05:18 PM @NotATether, you told me in pm the PK, with missing letters, is in a range of xxx and xxxxx so maybe i can search it this way. Yes but you see, it is more efficient to use the WifSolver program by @PawGo for problems like this, because something you write by hand may not be fully tested and not find private keys properly. Looks like you are trying to find private key with balance... This won't work for that. This is why: base on post history of the starter i believe he is trying to recover his own private key that is damaged and is missing a part of it. that is probably why the range looks like this. although if starter was more clear about what he is trying to do he would also get better help. I do have the fragment of the PK for which he's trying to recover the other part. The range search, which has already been running for a day, should take a few more days to finish on my hardware. It's 11 chars missing including checksum. 11 characters at the end? Should take seconds, not hours or days. It will take seconds on a GPU. But there are no GPU-bound programs that take a WIF and try to complete it (Bitcrack completely misses the key in the range), so I'm stuck with a cpu-bound solver running on 48 cores. Title: Re: Python HEX generator Range based Post by: WanderingPhilospher on April 26, 2021, 06:09:52 PM @NotATether, you told me in pm the PK, with missing letters, is in a range of xxx and xxxxx so maybe i can search it this way. Yes but you see, it is more efficient to use the WifSolver program by @PawGo for problems like this, because something you write by hand may not be fully tested and not find private keys properly. Looks like you are trying to find private key with balance... This won't work for that. This is why: base on post history of the starter i believe he is trying to recover his own private key that is damaged and is missing a part of it. that is probably why the range looks like this. although if starter was more clear about what he is trying to do he would also get better help. I do have the fragment of the PK for which he's trying to recover the other part. The range search, which has already been running for a day, should take a few more days to finish on my hardware. It's 11 chars missing including checksum. Title: Re: Python HEX generator Range based Post by: aliashraf on April 26, 2021, 11:39:24 PM A few points that folks overlooked in this thread:
1- Iterating from start to end requires an addition, i.e. 256 bit addition. From the programmer's perspective Python handles 256 bits integers trivially but python 2.5+ requires such variable to be defined as long explicitly, and it is good to know that we are not dealing with a one-cycle operation. 2- It looks that once the production of the output file is finished the journey is just started as OP wants to read this file and produce the corresponding public key for each row, comparing it with his target, so we need multiplication and modulo operations, it raises again performance issues. It is why we should use cryptographically optimized libraries wherever possible. 3-I think, generating a file firstly then feeding it to another python script as input for some computations is not the smartest plan for this use case, especially when we are talking Pythonic ;) Instead I'd do something like this: Code: //This is coded for python 2.5+ Title: Re: Python HEX generator Range based Post by: WanderingPhilospher on April 27, 2021, 02:12:01 AM A few points that folks overlooked in this thread: If that is what OP was really wanting, versus priv keys he can feed to some program to do the conversion, then I would not use pybitcoin; using it is a lot slower than other ways. When I ran tests, generating random private keys and converting them all the way down to BTC address, pybitcoin was 2.5 times slower on python 2.71- Iterating from start to end requires an addition, i.e. 256 bit addition. From the programmer's perspective Python handles 256 bits integers trivially but python 2.5+ requires such variable to be defined as long explicitly, and it is good to know that we are not dealing with a one-cycle operation. 2- It looks that once the production of the output file is finished the journey is just started as OP wants to read this file and produce the corresponding public key for each row, comparing it with his target, so we need multiplication and modulo operations, it raises again performance issues. It is why we should use cryptographically optimized libraries wherever possible. 3-I think, generating a file firstly then feeding it to another python script as input for some computations is not the smartest plan for this use case, especially when we are talking Pythonic ;) Instead I'd do something like this: Code: //This is coded for python 2.5+ Title: Re: Python HEX generator Range based Post by: Coding Enthusiast on April 27, 2021, 03:59:07 AM 11 characters at the end? Should take seconds, not hours or days. It depends on whether the key is compressed or uncompressed. For a compressed key you have to check about 22 million while for an uncompressed key the number is 5.8 billion. // Numbers are approximates, values usually are ±1 // Uncompressed ; Compressed // 1-5 -> 1 ; 1 // 6 -> 9 ; 1 // 7 -> 514 ; 3 // 8 -> 29,817 ; 117 // 9 -> 1,729,387 ; 6,756 // 10 -> 100,304,420 ; 391,815 // 11 -> 5,817,656,406 ; 22,725,222 // 12 -> ; 1,318,062,780 For the first case it takes about 2 minutes to check all the keys using FinderOuter https://i.imgur.com/I8BD6p8.jpg Title: Re: Python HEX generator Range based Post by: WanderingPhilospher on April 27, 2021, 07:41:52 AM 11 characters at the end? Should take seconds, not hours or days. It depends on whether the key is compressed or uncompressed. For a compressed key you have to check about 22 million while for an uncompressed key the number is 5.8 billion. // Numbers are approximates, values usually are ±1 // Uncompressed ; Compressed // 1-5 -> 1 ; 1 // 6 -> 9 ; 1 // 7 -> 514 ; 3 // 8 -> 29,817 ; 117 // 9 -> 1,729,387 ; 6,756 // 10 -> 100,304,420 ; 391,815 // 11 -> 5,817,656,406 ; 22,725,222 // 12 -> ; 1,318,062,780 For the first case it takes about 2 minutes to check all the keys using FinderOuter Ok, that might seem like a lot for your program, the FinderOuter, but I could check 5.8 billion in seconds. It's like people want to make finding 11 missing characters from the end harder, or only use a program that they know or have used before. Now all I can wonder is why the merit for you, for just telling how long it would take for you to find it with a slower program? Who knows... Title: Re: Python HEX generator Range based Post by: Coding Enthusiast on April 27, 2021, 07:56:15 AM Ok, that might seem like a lot for your program, the FinderOuter, but I could check 5.8 billion in seconds. Then you are more skilled than I.But please note that the check here is against an address not a public key so algorithms such as Pollard Kangaroos, and Baby Step Giant Step can't work. just telling how long it would take for you to find it with a slower program? Who knows... I'm not just reporting the time, I'm offering an existing solution and in case it wasn't clear the link to FinderOuter is found in my signature.Announcement: https://bitcointalk.org/index.php?topic=5214021.0 Source code: https://github.com/Coding-Enthusiast/FinderOuter Title: Re: Python HEX generator Range based Post by: WanderingPhilospher on April 27, 2021, 07:57:43 AM Ok, that might seem like a lot for your program, the FinderOuter, but I could check 5.8 billion in seconds. Then you are more skilled than I.But please note that the check here is against an address not a public key so algorithms such as Pollard Kangaroos, and Baby Step Giant Step can't work. just telling how long it would take for you to find it with a slower program? Who knows... I'm not just reporting the time, I'm offering an existing solution and in case it wasn't clear the link to FinderOuter is found in my signature.Announcement: https://bitcointalk.org/index.php?topic=5214021.0 Source code: https://github.com/Coding-Enthusiast/FinderOuter My bad, I read the OPs original post and he said he had the public keys; maybe he misspoke? Because with public keys or the address, one can use other programs. Even if address only, still wouldn't take long. In your example, I could solve with address only in a few seconds. (From OP) Quote I have the Public Keys so i try this script, maybe it exist a better solution !? Title: Re: Python HEX generator Range based Post by: aliashraf on April 27, 2021, 09:26:13 AM Instead I'd do something like this: If that is what OP was really wanting, versus priv keys he can feed to some program to do the conversion, then I would not use pybitcoin; using it is a lot slower than other ways. When I ran tests, generating random private keys and converting them all the way down to BTC address, pybitcoin was 2.5 times slower on python 2.7Code: //This is coded for python 2.5+ Title: Re: Python HEX generator Range based Post by: NotATether on April 27, 2021, 05:19:06 PM My bad, I read the OPs original post and he said he had the public keys; maybe he misspoke? Because with public keys or the address, one can use other programs. Even if address only, still wouldn't take long. In your example, I could solve with address only in a few seconds. (From OP) Quote I have the Public Keys so i try this script, maybe it exist a better solution !? Yes I do have his public key too. But if I can't verify that he gave me the correctly spelled private key then I won't even be able to Pollard's Kangaroo it (so far it finds nothing). I should probably ask for a photo of paper PK just to verify. Title: Re: Python HEX generator Range based Post by: Marshal TITO on April 27, 2021, 05:49:55 PM My bad, I read the OPs original post and he said he had the public keys; maybe he misspoke? Because with public keys or the address, one can use other programs. Even if address only, still wouldn't take long. In your example, I could solve with address only in a few seconds. (From OP) Quote I have the Public Keys so i try this script, maybe it exist a better solution !? Yes I do have his public key too. But if I can't verify that he gave me the correctly spelled private key then I won't even be able to Pollard's Kangaroo it (so far it finds nothing). I should probably ask for a photo of paper PK just to verify. Will send it to you when the 2 msg per day expired. Title: Re: Python HEX generator Range based Post by: aliashraf on April 28, 2021, 07:40:12 AM My bad, I read the OPs original post and he said he had the public keys; maybe he misspoke? Because with public keys or the address, one can use other programs. Even if address only, still wouldn't take long. In your example, I could solve with address only in a few seconds. (From OP) Quote I have the Public Keys so i try this script, maybe it exist a better solution !? Yes I do have his public key too. But if I can't verify that he gave me the correctly spelled private key then I won't even be able to Pollard's Kangaroo it (so far it finds nothing). I should probably ask for a photo of paper PK just to verify. Will send it to you when the 2 msg per day expired. |