Pages:
Author

Topic: Python HEX generator Range based - page 2. (Read 388 times)

legendary
Activity: 2352
Merit: 6089
bitcoindata.science
April 26, 2021, 07:55:03 AM
#7
I would like to have a Script like this

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
random.getrandbits(256)

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

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.
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.
newbie
Activity: 11
Merit: 2
April 26, 2021, 07:26:09 AM
#6
I would like to have a Script like this

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.



 
newbie
Activity: 25
Merit: 1
April 26, 2021, 07:20:08 AM
#5
Hi, you can use secrets library.. "pip install secrets"

Code:
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

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 ^^
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
April 26, 2021, 07:17:44 AM
#4
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.
legendary
Activity: 2870
Merit: 7490
Crypto Swap Exchange
April 26, 2021, 07:17:25 AM
#3
Since you're not being specific, i made something very simple

Code:
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

Code:
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.
legendary
Activity: 3038
Merit: 2166
Playgram - The Telegram Casino
April 26, 2021, 06:25:08 AM
#2
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?
newbie
Activity: 11
Merit: 2
April 26, 2021, 06:02:45 AM
#1
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
Pages:
Jump to: