Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: crofrihosl on September 09, 2019, 03:07:28 PM



Title: Python script for testing a bunch of bitcoin private keys
Post by: crofrihosl on September 09, 2019, 03:07:28 PM
hello,

can anyone help or direct me where i can find it

it will better if the script test files with 100k to 500k bitcoin privates keys


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: crofrihosl on September 09, 2019, 03:24:08 PM

do something like
- read public address from a file
- check for balance and tx
- print output

with more option:
- get the public key from the private key and test it with blockchain api
- check for balance and tx
- print output



Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: seoincorporation on September 09, 2019, 04:36:44 PM
The problem about this is that you need two steps, the first one (and the easy one) is to get the address from the private key, for that you can use a tool like this:

https://github.com/blockstack/pybitcoin

And the second step is the complex one... Verify the address balance, for this, you can use an API from some block explorer to verify if the address has balance, or another way is to do it directly with bitcoin core.

But i think the best way to do it and to save time is to import all those private keys to bitcoin core, that way you will not waste time calling the API to verify if they have balance or not.


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: ABCbits on September 09, 2019, 07:10:48 PM
The best way is make your own database which have column address and amount. There's big bottleneck if you use Bitcoin Core or block explorer API.
Combining your script with tools mentioned by @seoincorporation and query to local database would save lots of time.

And the second step is the complex one... Verify the address balance, for this, you can use an API from some block explorer to verify if the address has balance, or another way is to do it directly with bitcoin core.

Bitcoin Core don't index balance of each address, unless it's part of your wallet (including watch-only address). You could use chainstate and txindex though.

But i think the best way to do it and to save time is to import all those private keys to bitcoin core, that way you will not waste time calling the API to verify if they have balance or not.

I'm not sure if it's best way when we're talking about hundred thousand of Bitcoin address.


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: crofrihosl on September 09, 2019, 07:59:36 PM
The problem about this is that you need two steps, the first one (and the easy one) is to get the address from the private key, for that you can use a tool like this:

https://github.com/blockstack/pybitcoin

And the second step is the complex one... Verify the address balance, for this, you can use an API from some block explorer to verify if the address has balance, or another way is to do it directly with bitcoin core.

But i think the best way to do it and to save time is to import all those private keys to bitcoin core, that way you will not waste time calling the API to verify if they have balance or not.

thank you for replying

i used electrum to extract public address but crashing

can i find this?

SOMECODES.py  file_contain_private_keys.txt output>> file_contain_public_keys.txt



Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: Raja_MBZ on September 09, 2019, 10:35:12 PM
The best way is make your own database which have column address and amount. There's big bottleneck if you use Bitcoin Core or block explorer API.

@crofrihosl, if you're going to follow this approach (of creating your own database), the following Python code will definitely help you:

https://github.com/graymauser/btcposbal2csv


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: seoincorporation on September 10, 2019, 03:40:14 AM
The best way is make your own database which have column address and amount. There's big bottleneck if you use Bitcoin Core or block explorer API.
Combining your script with tools mentioned by @seoincorporation and query to local database would save lots of time.

And the second step is the complex one... Verify the address balance, for this, you can use an API from some block explorer to verify if the address has balance, or another way is to do it directly with bitcoin core.

Bitcoin Core don't index balance of each address, unless it's part of your wallet (including watch-only address). You could use chainstate and txindex though.

But i think the best way to do it and to save time is to import all those private keys to bitcoin core, that way you will not waste time calling the API to verify if they have balance or not.

I'm not sure if it's best way when we're talking about hundred thousand of Bitcoin address.

I think bitcoin core was able to show balance but as you say for that we have to add the address as watch only...

And about the best way you are right, is not the best way, is just the easy way.

I reply again because i found the python script i used in the past for the same propose, it's called coinkit:

Code:
from coinkit.keypair import BitcoinKeypair
k = BitcoinKeypair('5Jx4txgXUCe1kP8mBLEZrLSsZm9WRin8xijWvVW8RACzHn2ZzBH')
d = k.address()
print (d)

For more information look at: https://github.com/mflaxman/coinkit


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: pooya87 on September 10, 2019, 04:42:31 AM
you won't find any optimized scripts or tools to do what you want because that is not something that people normally want to do. you just don't suddenly come up with hundreds of thousands of keys wanting to check their balances. even big exchanges that handle millions of addresses add them little by little to their database.
so as @ETFbitcoin said you have to create your own. while doing that you have to know that the bottleneck is not just database lookups, it is also the EC multiplications of 500k times and the two hashes that you have to perform 500k times on each of them.

why do you have so many keys to check anyways?


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: crofrihosl on September 10, 2019, 12:10:38 PM
I reply again because i found the python script i used in the past for the same propose, it's called coinkit:
Code:
from coinkit.keypair import BitcoinKeypair
k = BitcoinKeypair('5Jx4txgXUCe1kP8mBLEZrLSsZm9WRin8xijWvVW8RACzHn2ZzBH')
d = k.address()
print (d)

For more information look at: https://github.com/mflaxman/coinkit

thank you for the 4 linescode :-*
but it not working for all keys

Code:
from coinkit.keypair import BitcoinKeypair
k = BitcoinKeypair('5JFJnRWLYgPV8vrhzmox8rHru42ACUnM8Y44eG7QtFqPUCyHdRP')
d = k.address()
print (d)

>getaddress.py
1crof2axcuUxNc6aBkNM9aoawoJxpf8vg

Code:
from coinkit.keypair import BitcoinKeypair
k = BitcoinKeypair('L3inaKfhAkUWJfDP3y7Cu26iAe7BsKPHu71NeZCXZzgVgdXMxrAR')
d = k.address()
print (d)

>getaddress.py
  File "getaddress.py", line 1

    >getaddress.py
    ^
SyntaxError: invalid syntax


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: crofrihosl on September 10, 2019, 12:59:47 PM
why do you have so many keys to check anyways?

many satoshi's bitcoin are missing out there for someone to take them 8)
i want to take my chances of getting one of this lost wallets ;D


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: Raja_MBZ on September 10, 2019, 01:09:45 PM
why do you have so many keys to check anyways?

many satoshi's bitcoin are missing out there for someone to take them 8)
i want to take my chances of getting one of this lost wallets ;D

Ridiculous. Why the hell did you even mention that "100k to 500k" range?


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: crofrihosl on September 10, 2019, 01:23:42 PM
why do you have so many keys to check anyways?

many satoshi's bitcoin are missing out there for someone to take them 8)
i want to take my chances of getting one of this lost wallets ;D

Ridiculous. Why the hell did you even mention that "100k to 500k" range?
this number help me to estimate the time needed to treat for big files all i do after is *10 or *100
500k few sec...etc


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: crofrihosl on September 10, 2019, 01:29:49 PM
i found the python script i used in the past for the same propose, it's called coinkit:

Code:
from coinkit.keypair import BitcoinKeypair
k = BitcoinKeypair('5Jx4txgXUCe1kP8mBLEZrLSsZm9WRin8xijWvVW8RACzHn2ZzBH')
d = k.address()
print (d)

For more information look at: https://github.com/mflaxman/coinkit

i made few changes
to read filess contain prvtkey
and give pubadd as output

can you please take a look and fix it :-\
Code:
from coinkit.keypair import BitcoinKeypair

with open("prvkey.txt","r") as f:
    in_prvkey = f.readlines()
in_prvkey = [x.strip() for x in in_prvkey]
f.close()
#print  in_prvkey

outfile = open("prvkey2add.txt","w")
for x in in_prvkey:
  k = BitcoinKeypair(x)
  print k
 
outfile.write(k.address(x)+"\n")
outfile.close()


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: crofrihosl on September 10, 2019, 07:29:20 PM

Assuming that private key is valid, that means the library doesn't support WIF (with compressed key) format. You might want to convert it to WIF (uncompressed key) or use another library such as https://github.com/ofek/bit (https://github.com/ofek/bit).

Besides, library mentioned by @seoincorporation is outdates (last commit in 2014)


yes my key valid and tested: 5JFJnRWLYgPV8vrhzmox8rHru42ACUnM8Y44eG7QtFqPUCyHdRP
this key not (5JFJnRWLYgPV8vrhzmox8rHru42ACUnM8Y44eG7QtFqPUCyHdRP)

i need to work offline  :-\  this wint help https://github.com/ofek/bit (https://github.com/ofek/bit).



could you please take a look and fix this :'(
Code:
from coinkit.keypair import BitcoinKeypair

with open("prvkey.txt","r") as f:
    in_prvkey = f.readlines()
in_prvkey = [x.strip() for x in in_prvkey]
f.close()
#print  in_prvkey

outfile = open("prvkey2add.txt","w")
for x in in_prvkey:
  k = BitcoinKeypair(x)
  print k
 
outfile.write(k.address(x)+"\n")
outfile.close()

-read private keys [and support all keys format] from a file
-give output public addresses all line by line [only addresses]
 :-[


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: pooya87 on September 11, 2019, 04:26:14 AM
why do you have so many keys to check anyways?

many satoshi's bitcoin are missing out there for someone to take them 8)
i want to take my chances of getting one of this lost wallets ;D

haha, cool.
as long as you realize you are wasting your time, it is cool to learn some coding and the underlying cryptography that bitcoin uses.
for your purpose you shouldn't be using a library. you have to write your own code for all the parts.

for starters the library that was introduced is in python, that is slow to begin with. additionally the functions aren't defined to be fast for huge loops.
this part alone will slow it down dramatically: https://github.com/mflaxman/coinkit/blob/8ce28ac4ff56e2320bf452d0559b83baf40b2b51/coinkit/keyspace.py#L25-L37
hashlib.Sha256 is also slow even though it is written in C but the way you are going to be using it in that library is going to be slow.

although one might wonder why you are even looping through base58 (WIF) keys if you are looping through random keys!


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: crofrihosl on September 11, 2019, 01:17:35 PM
why do you have so many keys to check anyways?

many satoshi's bitcoin are missing out there for someone to take them 8)
i want to take my chances of getting one of this lost wallets ;D

haha, cool.
as long as you realize you are wasting your time, it is cool to learn some coding and the underlying cryptography that bitcoin uses.
for your purpose you shouldn't be using a library. you have to write your own code for all the parts.

for starters the library that was introduced is in python, that is slow to begin with. additionally the functions aren't defined to be fast for huge loops.
this part alone will slow it down dramatically: https://github.com/mflaxman/coinkit/blob/8ce28ac4ff56e2320bf452d0559b83baf40b2b51/coinkit/keyspace.py#L25-L37
hashlib.Sha256 is also slow even though it is written in C but the way you are going to be using it in that library is going to be slow.

although one might wonder why you are even looping through base58 (WIF) keys if you are looping through random keys!
you just read my mind i was thinking
-when only generating privates keys took only few seconds
-when only generating both privates keys and public address took too many time slow
-even if i try to extract only addresses after generating the privates keys was slow too

any alternatives solutions for me? ??? i can't have my own library for now  :-\


Title: Re: Python script for testing a bunch of bitcoin private keys
Post by: keychainX on September 15, 2019, 01:37:24 PM
hello,

can anyone help or direct me where i can find it

it will better if the script test files with 100k to 500k bitcoin privates keys

First download blockparser from github and second convert all your private keys with above  mentioned tool to find a match.

very simple. block parser may take a while depending on your code, disk speed, memory etc.

Setting up a block parser you can read here https://countuponsecurity.com/2016/11/20/blockchain-brainwallet-cracking/

the rest is simple unix scritps

/KX