This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
forked from pierce403/keyhunter
-
Notifications
You must be signed in to change notification settings - Fork 8
/
keyhunter.py
executable file
·89 lines (64 loc) · 1.83 KB
/
keyhunter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python
import binascii
import os
import hashlib
import sys
# bytes to read at a time from file (10meg)
readlength=10*1024*1024
if len(sys.argv)!=2:
print "./keyhunter.py <filename>"
exit()
filename = sys.argv[1]
f = open(filename)
magic = '\x01\x30\x82\x01\x13\x02\x01\x01\x04\x20'
magiclen = len(magic)
##### start code from pywallet.py #############
__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
__b58base = len(__b58chars)
def b58encode(v):
""" encode v, which is a string of bytes, to base58.
"""
long_value = 0L
for (i, c) in enumerate(v[::-1]):
long_value += (256**i) * ord(c)
result = ''
while long_value >= __b58base:
div, mod = divmod(long_value, __b58base)
result = __b58chars[mod] + result
long_value = div
result = __b58chars[long_value] + result
# Bitcoin does a little leading-zero-compression:
# leading 0-bytes in the input become leading-1s
nPad = 0
for c in v:
if c == '\0': nPad += 1
else: break
return (__b58chars[0]*nPad) + result
def Hash(data):
return hashlib.sha256(hashlib.sha256(data).digest()).digest()
def EncodeBase58Check(secret):
hash = Hash(secret)
return b58encode(secret + hash[0:4])
########## end code from pywallet.py ############
# read through target file
# one block at a time
while True:
data = f.read(readlength)
if not data:
break
# look in this block for keys
x=0
while True:
# find the magic number
pos=data.find(magic,x)
#pos=data.find('\13\02\01\01\04\20',0)
if pos==-1:
break
print EncodeBase58Check('\x80'+data[pos+magiclen:pos+magiclen+32])
x+=(pos+1)
# are we at the end of the file?
if len(data) < readlength:
break
# make sure we didn't miss any keys at the end of the block
f.seek(f.tell()-(32+magiclen))
# code grabbed from pywallet.py