-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmnemonic-blake256.py
64 lines (45 loc) · 1.73 KB
/
mnemonic-blake256.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
#!/usr/bin/python3
from Crypto.Util.RFC1751 import key_to_english
import mnemonic
import binascii
import base62
from base58 import b58encode_check
from os.path import exists
import sys
from hashlib import blake2b
if len(sys.argv) > 2:
print("Too many arguments.")
quit()
elif len(sys.argv) == 2:
filename = sys.argv[1]
if not exists(filename):
print("File not found.")
quit()
else:
print("Filename not specified.")
quit()
def print_the_digest(digest):
# we need it also for bitcoin.encode_privkey()
digest_HEX = binascii.b2a_hex(digest).decode("utf-8")
print ("Hex:", digest_HEX)
print ("Base64:", binascii.b2a_base64(digest, newline=False).decode("utf-8"))
print ("Base62:", base62.encodebytes(digest))
print ("Base58Check:", b58encode_check(digest).decode("utf-8"))
if 16 <= len(digest) <= 32:
print ("BIP39 mnemonic:", mnemonic.Mnemonic('english').to_mnemonic(digest))
elif len(digest) == 64:
print ("BIP39 mnemonic (1):", mnemonic.Mnemonic('english').to_mnemonic(digest[:32]))
print ("BIP39 mnemonic (2):", mnemonic.Mnemonic('english').to_mnemonic(digest[32:]))
print (" * This digest is 512 bits long, so it's split in two parts")
print (" and this way two BIP39 mnemonic codes are produced.")
print ("RFC1751 mnemonic:", key_to_english(digest))
BLOCKSIZE = 2**16
my_blake2b_32 = blake2b(digest_size=32)
with open(filename, 'rb') as big_file:
file_buffer = big_file.read(BLOCKSIZE)
while len(file_buffer) > 0:
my_blake2b_32.update(file_buffer)
file_buffer = big_file.read(BLOCKSIZE)
digest_blake2b_32= my_blake2b_32.digest()
print("\n=== Blake2b-256 hash: ===\n")
print_the_digest(digest_blake2b_32)