-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateVanityKeypair.py
76 lines (70 loc) · 2.2 KB
/
generateVanityKeypair.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
from globals import *
clean = 49 * " "
def main():
try:
# Inputs #
prefix = getINPUT("Enter the desired prefix: ")
firstChar = prefix[0] if prefix else ""
if firstChar not in ["", "A", "B", "C", "D"]:
sys.exit("Try a prefix starting with A/B/C/D.")
suffix = getINPUT("Enter the desired suffix: ")
# Input Validation #
if any(chars not in BASE_32_ALPHABET for chars in prefix + suffix):
sys.exit("Try base32 inputs.")
prefixLen = len(prefix)
suffixLen = len(suffix)
approxSearchTime = validateSearchSpan(prefixLen + suffixLen)
searchingMoreForPrefix = prefixLen > suffixLen
prefix = f"G{prefix}"
# Main Keygen #
partials = getINPUT("Show partial matches? (Y/n): ") == "Y"
print(approxSearchTime)
startTime = time.time()
n = 0
while True:
if not n % 3200:
showSearching(startTime)
n += 1
keypair = Keypair.random()
PK = keypair.public_key
prefixMatch = PK.startswith(prefix)
suffixMatch = PK.endswith(suffix)
if prefixMatch and suffixMatch:
result = f"""\n
\tKeypair found in {n:,} attempts:
\tPublic Key: {PK}
\tSecret Key: {keypair.secret}\n
"""
sys.exit(result)
if not partials: continue
if searchingMoreForPrefix:
if not prefixMatch: continue
partial = f"{clean}—{PK[-6:]}"
else:
if not suffixMatch: continue
partial = f"{clean}{PK[:6]}—"
partialMatch = [
f"\r Partial Fit: {partial}",
f"\n Public Key: {PK}",
f"\n Secret Key: {keypair.secret}\n"
]
sys.stdout.write("".join(partialMatch))
except KeyboardInterrupt:
sys.exit("\nUser ended keypair search.")
def validateSearchSpan(totalInputLen):
match totalInputLen:
case span if span > 10:
sys.exit("Try shorter inputs.")
case 5:
return "Be advised: >30 min to compute."
case 6:
return "Be advised: >2 hrs to compute."
case 7:
return "Be advised: >10 hrs to compute."
case 8:
return "Be advised: >30 hrs to compute."
case 9:
return "Be advised: >3 days to compute."
case 10:
return "Be advised: >9 days to compute."
print(main())