Skip to content

Instantly share code, notes, and snippets.

@clementi
Last active June 18, 2019 21:44
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 clementi/5054b51d411e3cc5c951c40f597e750f to your computer and use it in GitHub Desktop.
Save clementi/5054b51d411e3cc5c951c40f597e750f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import secrets
import string
import sys
import os
def generate_passphrase(word_index, size):
words = []
for _ in range(size):
index = generate_index()
words.append(word_index[index])
return ' '.join(words)
def generate_index():
index = ""
for _ in range(5):
index += str(secrets.randbelow(6) + 1)
return index
def get_index_and_word(line):
index, word = tuple(filter(lambda part: part != '', line.strip().split('\t')))
return index, word
def build_word_index(word_file):
words = {}
for line in word_file:
index, word = get_index_and_word(line)
words[index] = word
return words
def get_wordlist_path():
homepath = os.getenv('HOME')
return f"{homepath}/.local/share/ppgen/eff_large_wordlist.txt"
def main():
size = 4 if len(sys.argv) < 2 else int(sys.argv[1])
wordlist_path = get_wordlist_path()
with open(wordlist_path) as word_file:
word_index = build_word_index(word_file)
passphrase = generate_passphrase(word_index, size)
print(passphrase)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment