Skip to content

Instantly share code, notes, and snippets.

@gelez
Created September 15, 2019 20:19
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 gelez/ca552cc4923dd47d20d5ce88491c25a6 to your computer and use it in GitHub Desktop.
Save gelez/ca552cc4923dd47d20d5ce88491c25a6 to your computer and use it in GitHub Desktop.
python implementation of password generator based on xkcd comics: https://imgs.xkcd.com/comics/password_strength.png
import math
import random
if __name__ == '__main__':
# configuration
wordcount = 7
separator = "_"
capitalize = False
# load popular english word list (found at https://github.com/dolph/dictionary)
wordsList = []
#with open('popular.txt') as f: # from
#with open('russian.txt') as f: # from https://github.com/danakt/russian-words
with open('turkishwords.txt') as f: # from turkish https://github.com/mertemin/turkish-word-list
wordsList = f.read().splitlines()
result = ""
# calculate and display entropy
entropy = wordcount * math.log(len(wordsList), 2)
print("The following password is good for " + str(entropy) + " bits of entropy: ")
for i in range(wordcount):
word = random.choice(wordsList).lower()
if capitalize:
word = word[:1].upper() + word[1:]
if i != 0:
result = result + separator + word
else:
result = word
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment