Marshal TITO (OP)
Newbie
Offline
Activity: 11
Merit: 2
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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
|
|
|
|
HeRetiK
Legendary
Offline
Activity: 3038
Merit: 2153
Playgram - The Telegram Casino
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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?
|
|
|
|
▄▄███████▄▄███████ ▄███████████████▄▄▄▄▄ ▄████████████████████▀░ ▄█████████████████████▄░ ▄█████████▀▀████████████▄ ██████████████▀▀█████████ █████████████████████████ ██████████████▄▄█████████ ▀█████████▄▄████████████▀ ▀█████████████████████▀░ ▀████████████████████▄░ ▀███████████████▀▀▀▀▀ ▀▀███████▀▀███████ | ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ Playgram.io ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ | ▄▄▄░░ ▀▄ █ █ █ █ █ █ █ ▄▀ ▀▀▀░░
| │ | ▄▄▄███████▄▄▄ ▄▄███████████████▄▄ ▄███████████████████▄ ▄██████████████▀▀█████▄ ▄██████████▀▀███▄██▐████▄ ██████▀▀████▄▄▀▀█████████ ████▄▄███▄██▀█████▐██████ ██████████▀██████████████ ▀███████▌▐██▄████▐██████▀ ▀███████▄▄███▄████████▀ ▀███████████████████▀ ▀▀███████████████▀▀ ▀▀▀███████▀▀▀ | | │ | ██████▄▄███████▄▄████████ ███▄███████████████▄░░▀█▀ ███████████░█████████░░█ ░█████▀██▄▄░▄▄██▀█████░█ █████▄░▄███▄███▄░▄██████ ████████████████████████ ████████████████████████ ██░▄▄▄░██░▄▄▄░██░▄▄▄░███ ██░░░█░██░░░█░██░░░█░████ ██░░█░░██░░█░░██░░█░░████ ██▄▄▄▄▄██▄▄▄▄▄██▄▄▄▄▄████ ███████████████████████ ███████████████████████ | | │ | ► | |
|
|
|
ABCbits
Legendary
Offline
Activity: 2982
Merit: 7821
Crypto Swap Exchange
|
Since you're not being specific, i made something very simple start = 0x0 end = 0xF path = './file.txt'
with open(path, 'w+') as f: for x in range(start,end+1): f.write(hex(x) + '\n')
The output should look like this 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf
But as @HeRetiK said, what do you want to accomplish? It's possible you fell to XY problem.
|
|
|
|
NotATether
Legendary
Offline
Activity: 1708
Merit: 7184
In memory of o_e_l_e_o
|
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 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.
|
|
|
|
archyone
Newbie
Offline
Activity: 25
Merit: 1
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
April 26, 2021, 11:20:08 AM |
|
Hi, you can use secrets library.. "pip install secrets" import secrets
for n in range(100): # replace 100 by your number of time bits = secrets.randbits(256) # replace 256 by your choosen range (here this is the number of bits) with open('result.txt', 'a') as file: file.write("\n" + hex(bits)[2:])
et voila ! ![Wink](https://bitcointalk.org/Smileys/default/wink.gif) 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 ^^
|
|
|
|
Marshal TITO (OP)
Newbie
Offline
Activity: 11
Merit: 2
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
April 26, 2021, 11:26:09 AM |
|
I would like to have a Script like this https://github.com/saracen/bitcoin-all-key-generatorin 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.
|
|
|
|
bitmover
Legendary
Offline
Activity: 2408
Merit: 6188
Crypto Swap Exchange🈺
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
April 26, 2021, 11:55:03 AM Last edit: April 26, 2021, 12:09:47 PM by bitmover |
|
I would like to have a Script like this https://github.com/saracen/bitcoin-all-key-generatorin 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: import random random.getrandbits(256)
this will output a 256-bit number, just like any bitcoin private key. I ran this here and it returned: 92190443112138794064351826137983695759100025828546020995296739378362186540927 To create a file you can use ETFBitcoin solution, like this: import random
path = './file.txt'
with open(path, 'w+') as f: f.write(str(random.getrandbits(256)))
https://en.bitcoin.it/wiki/Private_key#:~:text=In%20Bitcoin%2C%20a%20private%20key,range%200%2D9%20or%20A%2DF. 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.
|
|
|
|
Marshal TITO (OP)
Newbie
Offline
Activity: 11
Merit: 2
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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.
|
|
|
|
bitmover
Legendary
Offline
Activity: 2408
Merit: 6188
Crypto Swap Exchange🈺
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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: import secrets start = int('0000000000000000000000000000000000000000000000000000251462abc584',16) stop = start + 10000 hex(secrets.choice(range(start, stop))).zfill(64) You can change stop (10000) and start for whatever number you like To add to txt import secrets
path = './file.txt' start = int('0000000000000000000000000000000000000000000000000000251462abc584',16) stop = start + 10000
with open(path, 'w+') as f: f.write(hex(secrets.choice(range(start, stop))).zfill(64))
|
|
|
|
Marshal TITO (OP)
Newbie
Offline
Activity: 11
Merit: 2
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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: import secrets start = int('0000000000000000000000000000000000000000000000000000251462abc584',16) stop = start + 10000 hex(secrets.choice(range(start, stop))).zfill(64) You can change stop (10000) and start for whatever number you like To add to txt import secrets
path = './file.txt' start = int('0000000000000000000000000000000000000000000000000000251462abc584',16) stop = start + 10000
with open(path, 'w+') as f: f.write(hex(secrets.choice(range(start, stop))).zfill(64)) 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 ?!
|
|
|
|
bitmover
Legendary
Offline
Activity: 2408
Merit: 6188
Crypto Swap Exchange🈺
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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. 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: path = './file.txt' start = int('0000000000000000000000000000000000000000000000000000251462abc584',16) stop = start + 10000
with open(path, 'w+') as f: for i in range(10000): f.write(hex(start+i).zfill(64).replace("x","0")+'\n') 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:
|
|
|
|
BrewMaster
Legendary
Offline
Activity: 2114
Merit: 1293
There is trouble abrewing
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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.
|
There is a FOMO brewing...
|
|
|
Marshal TITO (OP)
Newbie
Offline
Activity: 11
Merit: 2
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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 ), 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 ![Roll Eyes](https://bitcointalk.org/Smileys/default/rolleyes.gif) Big thanks for help, solving this problem here.
|
|
|
|
WanderingPhilospher
Full Member
![*](https://bitcointalk.org/Themes/custom1/images/star.gif) ![*](https://bitcointalk.org/Themes/custom1/images/star.gif)
Offline
Activity: 1120
Merit: 235
Shooters Shoot...
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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: import secrets start = int('0000000000000000000000000000000000000000000000000000251462abc584',16) stop = start + 10000 hex(secrets.choice(range(start, stop))).zfill(64) You can change stop (10000) and start for whatever number you like To add to txt import secrets
path = './file.txt' start = int('0000000000000000000000000000000000000000000000000000251462abc584',16) stop = start + 10000
with open(path, 'w+') as f: f.write(hex(secrets.choice(range(start, stop))).zfill(64)) 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: arq1 = open('sequentialkeys.txt', 'a')
start = 0x0000000000000000000000000000000000000000000000000000251462abc584 increment = 0x2710 startplusincr = start + increment while (start < startplusincr): start = start+0x1 arq1.write((hex(start)).lstrip("0x").rstrip("L").zfill(64)+'\n')
Results file looks like this: 0000000000000000000000000000000000000000000000000000251462abc585 0000000000000000000000000000000000000000000000000000251462abc586 0000000000000000000000000000000000000000000000000000251462abc587 0000000000000000000000000000000000000000000000000000251462abc588 0000000000000000000000000000000000000000000000000000251462abc589 0000000000000000000000000000000000000000000000000000251462abc58a 0000000000000000000000000000000000000000000000000000251462abc58b 0000000000000000000000000000000000000000000000000000251462abc58c 0000000000000000000000000000000000000000000000000000251462abc58d 0000000000000000000000000000000000000000000000000000251462abc58e 0000000000000000000000000000000000000000000000000000251462abc58f 0000000000000000000000000000000000000000000000000000251462abc590 0000000000000000000000000000000000000000000000000000251462abc591 0000000000000000000000000000000000000000000000000000251462abc592 0000000000000000000000000000000000000000000000000000251462abc593 0000000000000000000000000000000000000000000000000000251462abc594 0000000000000000000000000000000000000000000000000000251462abc595 0000000000000000000000000000000000000000000000000000251462abc596 0000000000000000000000000000000000000000000000000000251462abc597 0000000000000000000000000000000000000000000000000000251462abc598 0000000000000000000000000000000000000000000000000000251462abc599 0000000000000000000000000000000000000000000000000000251462abc59a 0000000000000000000000000000000000000000000000000000251462abc59b 0000000000000000000000000000000000000000000000000000251462abc59c 0000000000000000000000000000000000000000000000000000251462abc59d 0000000000000000000000000000000000000000000000000000251462abc59e 0000000000000000000000000000000000000000000000000000251462abc59f ... 0000000000000000000000000000000000000000000000000000251462abec8e 0000000000000000000000000000000000000000000000000000251462abec8f 0000000000000000000000000000000000000000000000000000251462abec90 0000000000000000000000000000000000000000000000000000251462abec91 0000000000000000000000000000000000000000000000000000251462abec92 0000000000000000000000000000000000000000000000000000251462abec93 0000000000000000000000000000000000000000000000000000251462abec94
|
|
|
|
Marshal TITO (OP)
Newbie
Offline
Activity: 11
Merit: 2
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
April 26, 2021, 04:43:09 PM |
|
Perfect thank you !
|
|
|
|
NotATether
Legendary
Offline
Activity: 1708
Merit: 7184
In memory of o_e_l_e_o
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
April 26, 2021, 06:05:18 PM Last edit: April 26, 2021, 06:19:45 PM by NotATether |
|
@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.
|
|
|
|
WanderingPhilospher
Full Member
![*](https://bitcointalk.org/Themes/custom1/images/star.gif) ![*](https://bitcointalk.org/Themes/custom1/images/star.gif)
Offline
Activity: 1120
Merit: 235
Shooters Shoot...
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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. 11 characters at the end? Should take seconds, not hours or days.
|
|
|
|
aliashraf
Legendary
Offline
Activity: 1456
Merit: 1174
Always remember the cause!
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
April 26, 2021, 11:39:24 PM Last edit: April 26, 2021, 11:56:04 PM by aliashraf |
|
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 ![Wink](https://bitcointalk.org/Smileys/default/wink.gif) Instead I'd do something like this: //This is coded for python 2.5+
from pybitcoin import BitcoinPrivateKey
// check the repository here // https://github.com/blockstack/pybitcoin
start = long(someValueHex) stop = long( biggerValueHex) target = long(targetPubKeyHex) def generate (s,e): while s <= e: yield s //it is a generator rather than an ordinary function s += 1 yield 0
def searchForTarget: candid = generate(start, stop) while true: pk = next(candid) if pk == 0: print("Exhausted the search space, sorry, no good news :( " ) break private_key = BitcoinPrivateKey(pk) public_key = privatekey.publickey() if public_key == target: hex_private_key = private_key.toHex(); print("FOUND! :) /n %s" , %hex_private_key) break
|
|
|
|
WanderingPhilospher
Full Member
![*](https://bitcointalk.org/Themes/custom1/images/star.gif) ![*](https://bitcointalk.org/Themes/custom1/images/star.gif)
Offline
Activity: 1120
Merit: 235
Shooters Shoot...
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
April 27, 2021, 02:12:01 AM |
|
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 ![Wink](https://bitcointalk.org/Smileys/default/wink.gif) Instead I'd do something like this: //This is coded for python 2.5+
from pybitcoin import BitcoinPrivateKey
// check the repository here // https://github.com/blockstack/pybitcoin
start = long(someValueHex) stop = long( biggerValueHex) target = long(targetPubKeyHex) def generate (s,e): while s <= e: yield s //it is a generator rather than an ordinary function s += 1 yield 0
def searchForTarget: candid = generate(start, stop) while true: pk = next(candid) if pk == 0: print("Exhausted the search space, sorry, no good news :( " ) break private_key = BitcoinPrivateKey(pk) public_key = privatekey.publickey() if public_key == target: hex_private_key = private_key.toHex(); print("FOUND! :) /n %s" , %hex_private_key) break
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.7
|
|
|
|
Coding Enthusiast
Legendary
Offline
Activity: 1040
Merit: 2785
Bitcoin and C♯ Enthusiast
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
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://ip.bitcointalk.org/?u=https%3A%2F%2Fi.imgur.com%2FI8BD6p8.jpg&t=665&c=BPPJKBnGdgKjzA)
|
|
|
|
|