Author

Topic: Python HEX generator Range based (Read 423 times)

legendary
Activity: 1456
Merit: 1176
Always remember the cause!
April 28, 2021, 02:40:12 AM
#27
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.
Send it to me as well Wink
newbie
Activity: 11
Merit: 2
April 27, 2021, 12:49:55 PM
#26
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.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
April 27, 2021, 12:19:06 PM
#25
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.
legendary
Activity: 1456
Merit: 1176
Always remember the cause!
April 27, 2021, 04:26:13 AM
#24
Instead I'd do something like this:
Code:
//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
Slower than what? Are you suggesting implementing the lib for Python from scratch?
full member
Activity: 1232
Merit: 242
Shooters Shoot...
April 27, 2021, 02:57:43 AM
#23
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://bitcointalksearch.org/topic/the-finderouter-a-bitcoin-recovery-tool-v0160-2022-09-19-5214021
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 !?
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
April 27, 2021, 02:56:15 AM
#22
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://bitcointalksearch.org/topic/the-finderouter-a-bitcoin-recovery-tool-v0160-2022-09-19-5214021
Source code: https://github.com/Coding-Enthusiast/FinderOuter
full member
Activity: 1232
Merit: 242
Shooters Shoot...
April 27, 2021, 02:41:52 AM
#21
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...
legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
April 26, 2021, 10:59:07 PM
#20
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
full member
Activity: 1232
Merit: 242
Shooters Shoot...
April 26, 2021, 09:12:01 PM
#19
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

Instead I'd do something like this:
Code:
//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
legendary
Activity: 1456
Merit: 1176
Always remember the cause!
April 26, 2021, 06:39:24 PM
#18
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

Instead I'd do something like this:
Code:
//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
full member
Activity: 1232
Merit: 242
Shooters Shoot...
April 26, 2021, 01:09:52 PM
#17
@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.
legendary
Activity: 1568
Merit: 6660
bitcoincleanup.com / bitmixlist.org
April 26, 2021, 01:05:18 PM
#16
@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.
newbie
Activity: 11
Merit: 2
April 26, 2021, 11:43:09 AM
#15
Perfect thank you !
full member
Activity: 1232
Merit: 242
Shooters Shoot...
April 26, 2021, 11:34:31 AM
#14
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
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
Code:
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:

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

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

newbie
Activity: 11
Merit: 2
April 26, 2021, 11:31:55 AM
#13
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://bitcointalksearch.org/topic/need-help-with-python-scrict-private-key-search-5331951 ),
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 Roll Eyes Roll Eyes Roll Eyes

Big thanks for help, solving this problem here.
legendary
Activity: 2128
Merit: 1293
There is trouble abrewing
April 26, 2021, 11:11:57 AM
#12
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.
legendary
Activity: 2352
Merit: 6089
bitcoindata.science
April 26, 2021, 09:52:40 AM
#11
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.

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:


source: https://www.reddit.com/r/Bitcoin/comments/1ohwvu/bitcoin_your_money_is_secured_by_the_laws_of_the/
newbie
Activity: 11
Merit: 2
April 26, 2021, 09:16:55 AM
#10
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
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
Code:
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 ?!
legendary
Activity: 2352
Merit: 6089
bitcoindata.science
April 26, 2021, 08:27:16 AM
#9
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
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
Code:
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))
newbie
Activity: 11
Merit: 2
April 26, 2021, 07:22:28 AM
#8
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.



legendary
Activity: 2352
Merit: 6089
bitcoindata.science
April 26, 2021, 06: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, 06: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, 06: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, 06: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, 06: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: 3150
Merit: 2185
Playgram - The Telegram Casino
April 26, 2021, 05: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, 05: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
Jump to: