forked from hclivess/Bismuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vanity.py
77 lines (65 loc) · 2.62 KB
/
vanity.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
import os
import sys
import logging
from logging.handlers import RotatingFileHandler
from Crypto import Random
#from Crypto.Hash import SHA
from Crypto.PublicKey import RSA
#from Crypto.Signature import PKCS1_v1_5
import hashlib
from multiprocessing import Process
from multiprocessing import freeze_support
desired = ["hclivess", "bismuth", "crypto"]
threads = 6
def search():
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
logFile = 'vanity.log'
my_handler = RotatingFileHandler(logFile, mode='a', maxBytes=5 * 1024 * 1024, backupCount=2, encoding=None, delay=0)
my_handler.setFormatter(log_formatter)
my_handler.setLevel(logging.INFO)
app_log = logging.getLogger('root')
app_log.setLevel(logging.INFO)
app_log.addHandler(my_handler)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s %(funcName)s(%(lineno)d) %(message)s')
ch.setFormatter(formatter)
app_log.addHandler(ch)
# key maintenance
if os.path.isfile("privkey.der") is True:
app_log.info("Client: privkey.der found")
else:
address = ""
while not any(x in address for x in desired):
# generate key pair and an address
random_generator = Random.new().read
key = RSA.generate(4096, random_generator)
public_key = key.publickey()
private_key_readable = str(key.exportKey())
public_key_readable = str(key.publickey().exportKey())
address = hashlib.sha224(public_key_readable).hexdigest() # hashed public key
app_log.info('Generating vanity attempt: ' + address)
# generate key pair and an address
app_log.info("Client: Your address: " + str(address))
app_log.info("Client: Your private key: " + str(private_key_readable))
app_log.info("Client: Your public key: " + str(public_key_readable))
pem_file = open("privkey.der", 'a')
pem_file.write(str(private_key_readable))
pem_file.close()
pem_file = open("pubkey.der", 'a')
pem_file.write(str(public_key_readable))
pem_file.close()
address_file = open("address.txt", 'a')
address_file.write(str(address) + "\n")
address_file.close()
if __name__ == '__main__':
freeze_support() #must be this line, dont move ahead
instances = range(threads)
print(instances)
for q in instances:
p = Process(target=search, args=())
p.start()
print("thread {} started".format(p)
for q in instances:
p.join()
p.terminate()