-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitcoinGenerator.py
111 lines (94 loc) · 3.2 KB
/
bitcoinGenerator.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
from hdwallet import HDWallet
import binascii
import multiprocessing as mp
import time
import uuid
import os
from random import randrange
import sys
import json
class Counter(object):
def __init__(self, initval=0):
self.val = mp.Value('i', initval)
self.lock = mp.Lock()
def increment(self, n):
with self.lock:
self.val.value += n
if self.val.value % 10 == 0:
print(f"Attempts made: {self.val.value} * 10000")
def value(self):
with self.lock:
return self.val.value
class Solver:
def __init__(self, process, computer, wallets, counter, flag, verbose=False):
self.targets = wallets
self.verbose = verbose
self.run = True
self.flag = flag
self.process = process
self.random_value = f"{computer}{process}"
self.counter = counter
self.current = 0
def start(self):
self.run = True
while self.run and self.flag.value() == 0:
self.generate()
def stop(self):
self.run = False
def random(self):
# from bitcoin project
return str(self.random_value) \
+ str(os.urandom(32).hex()) \
+ str(randrange(2 ** 256)) \
+ str(int(time.time() * 1000000)) \
def generate(self):
hdwallet = HDWallet()
hexSeed = binascii.hexlify(self.random().encode())
hdwallet.from_seed(hexSeed)
pubAdr = hdwallet.p2pkh_address()
wif = hdwallet.wif()
if self.verbose:
print(f"Proccess: {self.process}")
print(f"Key WIF: {wif}")
print(f"Key address: {pubAdr}")
if pubAdr in self.targets:
print("KEY FOUND!!!")
dump_str = json.dumps(hdwallet.dumps(), indent=4, ensure_ascii=False)
print(dump_str)
self.write(dump_str)
self.flag.increment(1)
# nice found!!!
# do something
self.current += 1
if self.current == 10000:
self.counter.increment(1)
self.current = 0
def write(self, wallet):
fhand = open("keys.txt", 'a+')
fhand.write(str(wallet))
fhand.write("\n###########################################\n")
fhand.close()
def generate(index, verbose, computer, wallets, counter, flag):
print(f"Process Started {index}")
solver = Solver(index, computer, wallets, counter, flag, verbose)
solver.start()
if __name__ == "__main__":
print("START")
counter = Counter()
flag = Counter()
verbose = False
if len(sys.argv) == 2 and sys.argv[1] == "--verbose":
verbose = True
fhand = open("wallets.txt")
wallets = set(fhand.readlines())
fhand.close()
computer = uuid.UUID(int=uuid.getnode())
# generate(1, verbose, computer, wallets, counter)
print("Cores on machine to be used:", mp.cpu_count())
print("Addresses to be used:", len(wallets))
procs = [mp.Process(target=generate, args=(index, verbose, computer, wallets, counter, flag,)) for index in range(mp.cpu_count())]
for p in procs: p.start()
for p in procs: p.join()
#12ib7dApVFvg82TXKycWBNpN8kFyiAN1dr
# compile to executable
# change address of wallets