Created
September 15, 2019 20:19
-
-
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
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
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