Last active
October 9, 2020 01:06
-
-
Save tofti/108da815d2e4d64c20315d78f466c58e to your computer and use it in GitHub Desktop.
python full dictionary to bip39 word list
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
from urllib.request import urlopen | |
from hashlib import sha256 | |
from os.path import expanduser | |
def main(): | |
seed_words_url = 'https://raw.githubusercontent.com/bitcoin/bips/master/bip-0039/english.txt' | |
seed_words_file = urlopen(seed_words_url) | |
seed_words = seed_words_file.read().decode("utf8").split("\n") | |
seed_words_count = len(seed_words) | |
dictionary_words_url = 'https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt' | |
dictionary_words_file = urlopen(dictionary_words_url) | |
dictionary_words = dictionary_words_file.read().decode("utf8").split("\n") | |
freq = [0] * seed_words_count | |
output_file = open(expanduser("~") + '\output.csv', 'w') | |
for dictionary_word in dictionary_words: | |
dictionary_word = dictionary_word.replace('\r','') | |
sha = sha256() | |
sha.update(dictionary_word.encode('utf-8')) | |
sha.hexdigest() | |
seed_word_idx = int(sha.hexdigest(), 16) % seed_words_count | |
output_file.write(dictionary_word + ',' + seed_words[seed_word_idx] + '\n') | |
freq[seed_word_idx] = freq[seed_word_idx] + 1 | |
freq_str = [str(f) for f in freq] | |
output_file.write("\n" + ",".join(freq_str)) | |
output_file.close() | |
if __name__ == "__main__": main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment