Skip to content

Instantly share code, notes, and snippets.

@filips123
Created January 27, 2019 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filips123/2fe0bfb7f5453760549004502c869f16 to your computer and use it in GitHub Desktop.
Save filips123/2fe0bfb7f5453760549004502c869f16 to your computer and use it in GitHub Desktop.
Generation of Slovenian BIP0039 wordlist
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