forked from 1200wd/py-vanitygen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vanitygen.py
executable file
·120 lines (104 loc) · 3.55 KB
/
vanitygen.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# coineva vanitygen.py
# Copyright (C) 2016 February
# 1200 Web Development
# http://1200wd.com/
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
#
# Script adjusted for a CTF purpouse.
#
#
#
import os
import sys
from bitcoinlib.keys import HDKey
import timeit
from time import sleep
import random
import multiprocessing
address = 'Your address here'
witness_type = 'segwit'
processors = 8
parts = int((2**32)/processors)
def address_search(search_for=address, multiplier = 0):
global witness_type
global parts
privkey = int(parts * multiplier)
address = ''
count = 0
start = timeit.default_timer()
#bech32 = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
#base58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
#is_bech32 = True
#is_base58 = True
#for letter in search_for:
# if letter not in bech32:
# is_bech32 = False
# if letter not in base58:
# is_base58 = False
#if not (is_bech32 or is_base58):
# raise ValueError(f"This is not a valid base58 or bech32 search string: {search_for}")
#if is_base58 and not is_bech32:
# print ("witness type p2sh-segwit")
# witness_type = 'p2sh-segwit'
#print(f"Searching for {search_for}, witness_type is {witness_type} (pid {os.getpid()})")
print(f"Starting address search: process {multiplier} (pid {os.getpid()})")
while not search_for in address:
privkey += 1
k = HDKey(witness_type='legacy', key = privkey, network='testnet', compressed=False) #forcing legacy for CTF
address = k.address()
count += 1
if not count % 10000:
print("(%d) Searched %d in %d seconds (pid %d) : %s - %d" % (multiplier, count, timeit.default_timer()-start, os.getpid(), address, privkey))
if count == parts:
print("Process (pid %d) did not find key in slice." % os.getpid())
return
print("Found address: %s" % address)
print("Private key HEX: %s" % k.private_hex)
print("Private key INT: %d" % privkey)
print("Time to execute: %d seconds" % (timeit.default_timer()-start))
return((address, k.private_hex))
def check_finish(plist):
for p in plist:
if not p.is_alive():
return True
return False
def kill_em_all(plist):
for p in plist:
p.terminate()
def main():
global address
global processors
# print(multiprocessing.cpu_count())
print("Starting %d processes" % processors)
ps = []
for i in range(processors):
print("Starting process %d" % i)
p = multiprocessing.Process(target=address_search, kwargs={'search_for': address, 'multiplier': i})
p.start()
ps.append(p)
while True:
if check_finish(ps):
kill_em_all(ps)
sys.exit(0)
sleep(.1)
# print(ps)
# print('Main process exiting')
if __name__ == '__main__':
main()