Created
July 21, 2016 14:03
-
-
Save IntegersOfK/00103c8b70b7652f82d5a9eeda73953d to your computer and use it in GitHub Desktop.
A python sample snippet for reordering bip39 mnemonic seed words into a valid bip39 seed (corrects word order to fix checksum/compliance with bip39)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This snippet takes words intended for a bip39 mnemonic seed as a list and reorders them into a seed where the checksum validates. | |
#Often people want to choose their own seed words but the resulting order doesn't adhere to the bip39 specification, | |
#This is a way to force your favourite words into a valid hd bip39 seed. Disclaimer: Use true random entropy to select your words! | |
#All possible combinations are written to a text file, but that's probably going to be a lot of choice so you should probably | |
#Limit the number of itterations or cancel it a ways into processing | |
import itertools | |
import os | |
import binascii | |
import mnemonic | |
#sample words, go make your own at https://dcpos.github.io/bip39/ | |
word_list = ["situate", "summer", "amused", "reunion", "spare", "school", "assume", "wolf", "embark", "share", "repeat", "bar"] | |
def make(): | |
m = mnemonic.Mnemonic('english') | |
text_file = open("combos_valid.txt", "w") | |
for subset in itertools.permutations(word_list, len(word_list)): | |
words_to_write = [] | |
for word in subset: | |
words_to_write.append(word) | |
if len(subset) == len(word_list): | |
if m.check(' '.join(words_to_write)): | |
for w in words_to_write: | |
text_file.write(w + ' ') | |
text_file.seek(-1, os.SEEK_CUR) | |
text_file.write('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello sir ..how can i use this script ..any tutorial i can look at ..pls reply ..my mnemonic seed is not in order after i inserted in my nano s after update resulted in factory reset..thank u..