-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgerman_passphrase.py
More file actions
37 lines (32 loc) · 907 Bytes
/
german_passphrase.py
File metadata and controls
37 lines (32 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
import math
import os
def load(wordsfile):
wordlist = []
with open(wordsfile, encoding="utf-8") as f:
for line in f:
wordlist.append(line.split("\n")[0])
return wordlist
def getword(wordlist,maxlen,minlen):
while True:
byte = math.ceil(math.log2(len(wordlist)) / 8)
random = os.urandom(byte)
number = int.from_bytes(random, byteorder=sys.byteorder) % len(wordlist)
word = wordlist[number]
if (len(word) <= maxlen and len(word) >= minlen):
return word
if __name__ == '__main__':
words = 4
min = 5
max = 12
if len(sys.argv) > 1:
words = int(sys.argv[1])
if len(sys.argv) > 2:
min = int(sys.argv[2])
if len(sys.argv) > 3:
max = int(sys.argv[3])
wordlist = load("germanwords-typical.txt")
phrase = ""
for i in range(0,words):
phrase = phrase + (getword(wordlist,max,min)) + " "
print(phrase)