3 PASSWORD_MIN_BITS_ENTROPY = 256
7 return open('/usr/share/dict/words')
8 except FileNotFoundError:
9 return open(' /usr/dict/words')
11 with open_dict() as dict_file:
12 dict_words = dict_file.readlines()
14 dict_word_count = len(dict_words)
16 passphrase_word_count = math.ceil(math.log(2**PASSWORD_MIN_BITS_ENTROPY, dict_word_count))
18 bytes_entropy_per_word = math.ceil(math.log(dict_word_count, 2**8))
20 print(bytes_entropy_per_word)
24 return dict_words[int.from_bytes(os.urandom(bytes_entropy_per_word), byteorder='little')].strip()
28 passphrase = ' '.join(rand_word() for i in range(passphrase_word_count))