forked from spooknik/Bitcoin-wallet-cracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc.py
198 lines (159 loc) · 7.03 KB
/
bc.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/python3
import hashlib
import os
import random
import binascii
import ecdsa
import base58
import datetime
import webbrowser
import PySimpleGUI as sg
from json import (load as jsonload, dump as jsondump)
from os import path
import json
import hmac
import base64
start_time = datetime.datetime.now()
def bip(num):
with open('BIP0039.txt', 'r') as f:
words = f.read().split()
for word in words:
sent = [random.choice(words)
for word in range(int(num))]
return ' '.join(sent)
def passw(filename):
try:
with open(filename, 'r') as f:
words = f.read().split()
for word in words:
sent = [random.choice(words)
for word in range(int(1))]
return ' '.join(sent)
except FileNotFoundError:
pass
except TypeError:
pass
def hmac512(mnemonic, passphrase):
d = mnemonic+' '+ passphrase
return d
def master(hmacsha512):
return hashlib.sha256(hmacsha512.encode("utf-8")).hexdigest().upper()
def pubkey(masterkey):
privatekey = binascii.unhexlify(masterkey)
s = ecdsa.SigningKey.from_string(privatekey, curve = ecdsa.SECP256k1)
return '04' + binascii.hexlify(s.verifying_key.to_string()).decode('utf-8')
def addr(public_key):
output = []; alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var = hashlib.new('ripemd160')
var.update(hashlib.sha256(binascii.unhexlify(public_key.encode())).digest())
var = '00' + var.hexdigest() + hashlib.sha256(hashlib.sha256(binascii.unhexlify(('00' + var.hexdigest()).encode())).digest()).hexdigest()[0:8]
count = [char != '0' for char in var].index(True) // 2
n = int(var, 16)
while n > 0:
n, remainder = divmod(n, 58)
output.append(alphabet[remainder])
for i in range(count): output.append(alphabet[0])
return ''.join(output[::-1])
def wif(masterkey):
var80 = "80"+masterkey
var = hashlib.sha256(binascii.unhexlify(hashlib.sha256(binascii.unhexlify(var80)).hexdigest())).hexdigest()
return str(base58.b58encode(binascii.unhexlify(str(var80) + str(var[0:8]))), 'utf-8')
def database(address):
with open("data-base", "r") as m:
add = m.read().split()
for ad in add:
continue
if address in add:
data = open("Win.txt","a")
data.write("Bingo " + str(sect)+"\n" +str(address)+"\n"+str(WIF)+"\n"+"\n")
data.close()
return 'Bingo'
else:
i = 'No luck'
return i
SETTINGS_FILE = path.join(path.dirname(__file__), r'settings_file.cfg')
DEFAULT_SETTINGS = {'theme': sg.theme()}
SETTINGS_KEYS_TO_ELEMENT_KEYS = {'theme': '-THEME-'}
def load_settings(settings_file, default_settings):
try:
with open(settings_file, 'r') as f:
settings = jsonload(f)
except Exception as e:
sg.popup_quick_message(f'exception {e}', 'No settings file found... will create one for you', keep_on_top=True, background_color='red', text_color='white')
settings = default_settings
save_settings(settings_file, settings, None)
return settings
def save_settings(settings_file, settings, values):
if values:
for key in SETTINGS_KEYS_TO_ELEMENT_KEYS:
try:
settings[key] = values[SETTINGS_KEYS_TO_ELEMENT_KEYS[key]]
except Exception as e:
print(f'Problem updating settings from window values. Key = {key}')
with open(settings_file, 'w') as f:
jsondump(settings, f)
sg.popup('Settings saved')
def create_settings_window(settings):
sg.theme(settings['theme'])
def TextLabel(text): return sg.Text(text+':', justification='r', size=(15,1))
layout = [ [sg.Text('Settings', font='Any 15')],
[TextLabel('Theme'),sg.Combo(sg.theme_list(), size=(20, 20), key='-THEME-')],
[sg.Button('Save'), sg.Button('Exit')] ]
window = sg.Window('Settings', layout, keep_on_top=True, finalize=True)
for key in SETTINGS_KEYS_TO_ELEMENT_KEYS:
try:
window[SETTINGS_KEYS_TO_ELEMENT_KEYS[key]].update(value=settings[key])
except Exception as e:
print(f'Problem updating PySimpleGUI window from settings. Key = {key}')
return window
def create_main_window(settings):
sg.theme(settings['theme'])
menu_def = [['&Menu', ['&Settings', 'E&xit']]]
layout = [[sg.Menu(menu_def)],
[sg.Text('Number of mnemonic words', size=(30,1), font=('Comic sans ms', 10)),
sg.Spin(values=('3', '6', '9', '12', '15', '18', '21', '24'),size=(3,1), key='num'), sg.Text('', size=(17,1))],
[sg.Text('This program has been running for... ', size=(30,1), font=('Comic sans ms', 10)),
sg.Text('', size=(30,1), font=('Comic sans ms', 10), key='_DATE_')],
[sg.Text('')],
[sg.Output(size=(87, 20), font=('Comic sans ms', 8), key='out')],
[sg.Text('Passwords file', size=(12,1), font=('Comic sans ms', 10)),sg.In(size=(65, 1),key='-in-'), sg.FileBrowse()],
[sg.Button('Start/Stop', font=('Comic sans ms', 10))]]
return sg.Window('Bitcoin wallet cracker',
layout=layout,
default_element_size=(9,1))
def main():
window, settings = None, load_settings(SETTINGS_FILE, DEFAULT_SETTINGS )
generator = False
while True:
if window is None:
window = create_main_window(settings)
event, values = window.Read(timeout=10)
window.Element('_DATE_').Update(str(datetime.datetime.now()-start_time))
if event in (None, 'Exit'):
break
elif event == 'Start/Stop':
generator = not generator
if generator:
filename = values['-in-'].rstrip()
num = values['num']
mnemonic = bip(num)
passphrase = passw(filename)
hmacsha512 = hmac512(mnemonic, passphrase)
masterkey = master(hmacsha512)
public_key = pubkey(masterkey)
address = addr(public_key)
WIF = wif(masterkey)
data_base = database(address)
print('mnemonic and passphrase: '+str(mnemonic)+ ' ' +str(passphrase)+'\n'+
'private key: '+str(masterkey)+'\n'+
'address: '+str(address)+'\n'+
'wif: '+str(WIF)+"\n"+
'address with balance: '+str(data_base)+'\n\n')
elif event == 'Settings':
event, values = create_settings_window(settings).read(close=True)
if event == 'Save':
window.close()
window = None
save_settings(SETTINGS_FILE, settings, values)
window.Close()
main()