Created
January 27, 2019 16:54
-
-
Save filips123/2fe0bfb7f5453760549004502c869f16 to your computer and use it in GitHub Desktop.
Generation of Slovenian BIP0039 wordlist
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 random import randint | |
import sys | |
COMMON = 'common.txt' | |
MIN_LENGTH = 4 | |
MAX_LENGTH = 8 | |
NUM = 2048 | |
def condition(word): | |
# Check length | |
# Check if ASCII | |
# Check if letter | |
# Check if lowercase | |
return \ | |
MIN_LENGTH <= len(word) <= MAX_LENGTH and \ | |
all(ord(char) < 128 and char.isalpha() and char.islower() for char in word) | |
def main(): | |
# Read all files | |
words = [] | |
for input in sys.argv[1:]: | |
with open(input) as file: | |
words += file.read().splitlines() | |
# Check conditions | |
words = [word for word in words if condition(word)] | |
# Remove duplicates | |
words = list(dict.fromkeys(words)) | |
# Sort alphabetically | |
words.sort() | |
# Remove some not common words | |
with open(COMMON) as file: | |
common = file.read().splitlines() | |
orig = words[:] | |
words = [] | |
for value in orig: | |
if randint(1, 10) <= 5 or value in common: | |
words.append(value) | |
# Remove similar words | |
orig = words[:] | |
words = [] | |
for key, value in enumerate(orig): | |
if key > 0: | |
if not orig[key - 1][:MIN_LENGTH] == value[:MIN_LENGTH]: | |
words.append(value) | |
# Remove words | |
while len(words) > NUM: | |
del words[randint(0, len(words))] | |
# Re run if too little words | |
if len(words) < NUM: | |
main() | |
return | |
# Write to file | |
with open('bip0039.txt', 'w') as file: | |
for word in words: | |
file.write('%s\n' % word) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment