-
Notifications
You must be signed in to change notification settings - Fork 6
/
bip39checksum.py
executable file
·63 lines (49 loc) · 1.41 KB
/
bip39checksum.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
#!/usr/bin/python3
import argparse
import sys
import mnemonic
import os
wordsfile = f"{sys.path[0]}/english.txt"
""" parsing arguments """
def parse_arguments():
global args
parser = argparse.ArgumentParser("bip39checksum.py")
parser.add_argument("-s", "--sequence", help="Specify sequence words file \
to check. Single line, words separated by a space", type=str, required=True)
args = parser.parse_args()
def clear():
# for windows
if os.name == 'nt':
_ = os.system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = os.system('clear')
def main():
try:
f = open(wordsfile)
english = f.read().strip().split('\n')
f.close()
except:
print("ERROR reading bip39 vocabulary")
sys.exit()
try:
f = open(sequence)
words = f.read().strip()
f.close()
if len(words.split(' ')) != 23:
print("ERROR: it does not seem 23 words sequence")
sys.exit()
except:
print("ERROR: error while reading your 23 words bip39 sequence")
sys.exit()
m = mnemonic.Mnemonic('english')
clear()
print("::Tested valid bip39 sequences::\n")
for word in english:
seq = "%s %s" % (words, word)
if m.check(seq):
print(seq)
if __name__ == "__main__":
parse_arguments()
sequence = args.sequence
main()