· 8 years ago · May 20, 2018, 04:26 PM
1import itertools
2import sqlite3
3
4import binascii
5import more_itertools as mit
6import requests
7from bip32utils import BIP32Key
8from mnemonic import Mnemonic
9from electrum import Network
10from electrum.util import json_encode, print_msg
11import json
12n = Network()
13n.start()
14
15conn = sqlite3.connect('btc.db')
16c = conn.cursor()
17
18c.execute('''
19CREATE TABLE IF NOT EXISTS phrases (phrase text primary key, valid integer)
20''')
21
22m = Mnemonic('english')
23target = '3CcxyPhyvyc3S9UuPfu42GNZLvVVV11Uk8'
24
25with open('words.txt') as f:
26 words = f.read().split('\n')
27
28i = 0
29while True:
30 combi = list(mit.random_permutation(words, 12))
31 phrase = ','.join(combi)
32
33 conn = sqlite3.connect('btc.db')
34 cursor = conn.cursor()
35 cursor.execute('SELECT * FROM phrases WHERE phrase=\'%s\'' % phrase)
36 if not cursor.fetchone():
37 cursor.execute('INSERT INTO phrases VALUES (\'%s\', %d)' % (phrase, 0))
38 conn.commit()
39 i += 1
40 try:
41 res = m.to_entropy(combi)
42 res = binascii.hexlify(res)
43 key = BIP32Key.fromEntropy(res)
44 address = key.Address()
45
46 #h = n.synchronous_get(('blockchain.address.get_balance',[address]))
47
48 #bal = h.get('confirmed')
49 bal = 'unknown'
50 print(address, bal, i, combi)
51
52 cursor.execute('UPDATE phrases SET valid=1 WHERE phrase=\'%s\'' % phrase)
53 conn.commit()
54
55 if address != target:
56 continue
57
58 exit()
59 except Exception:
60 pass
61 finally:
62 conn.close()