-
Notifications
You must be signed in to change notification settings - Fork 2
/
make-seed-simple.py
38 lines (28 loc) · 1.16 KB
/
make-seed-simple.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
#!/usr/bin/python3
from mnemonic import Mnemonic
from os.path import exists
from os import urandom
from hashlib import sha256
from Crypto.Util.strxor import strxor
def get_random_bytes(howmany):
if exists("/dev/random"):
with open("/dev/random", 'rb') as f:
return f.read(howmany)
else:
print ("/dev/random not found, using os.urandom instead.")
return urandom(howmany)
user_entropy = input("Type some random data (from dice rolls, decks of cards, etc): ").encode('utf-8')
myrandom = strxor(get_random_bytes(32), sha256(user_entropy+urandom(1024)).digest())
print ("\n BIP39 mnemonic, to be used as salt for the \"doubleslow-base.py\": \n\n")
words = Mnemonic('english').to_mnemonic(myrandom)
test = Mnemonic('english').to_entropy(words)
# Hmmm, It works without this line:
#test = bytes(test)
if test == myrandom:
print(words)
else:
print("Oops. Fatal error.")
quit();
print ("\n\n* * * Warning: The output is not deterministic!")
print ( " With the same user input you will get different output.")
print ( " The script is mixing the user entropy with computer-generated entropy.")