-
Notifications
You must be signed in to change notification settings - Fork 2
/
random-words.py
97 lines (70 loc) · 2.25 KB
/
random-words.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/python3
import random
import sys
from randomness_choice import random_below
from randomness_choice import use_mouse
filename_list = [
"wordlist.txt",
"/usr/share/keepassxc/wordlists/eff_large.wordlist",
"/usr/share/dict/american-english",
"/usr/share/dict/british-english",
"/usr/share/dict/cracklib-small",
]
filename = ""
if len(sys.argv) > 2:
print("Too many arguments.")
quit()
elif len(sys.argv) == 2:
filename = sys.argv[1]
if filename == "":
from os.path import exists
for filename_i in filename_list:
if exists(filename_i):
filename = filename_i
break
if filename == "":
print("Dictionary file not found.")
quit()
print("Using dictionary:", filename)
with open(filename) as f:
mywordlist = [line.rstrip() for line in f]
random_words = list()
exclusive_range = len(mywordlist)
print("The list of words contains", exclusive_range, "elements.")
if exclusive_range < 2048:
print("Too small list of words.")
quit()
while True:
try:
how_many = int(input("How many random words you need: "))
except ValueError as detail:
print(" Wrong input.", detail)
continue
if how_many < 1:
print ("It does not make senese to ask for a less than 1 random word.")
else:
break
while True:
print("Do you want to use the mouse as a randomness source?")
print ("Enter \"0\" (zero) or \"no\" to not ask for a mouse movements.")
mouse_reply = input("Or just press \"enter\" to continue: ")
if (mouse_reply == "0") or (mouse_reply == "no"):
print ("The mouse will not be used as a randomness source.")
use_mouse(False)
break
elif (mouse_reply == "yes") or (mouse_reply == "yes") or (mouse_reply == ""):
print ("The mouse will be used as a randomness source.")
use_mouse(True)
break
else:
print ("Invalid response.")
for counter in range(how_many):
random_number = random_below(exclusive_range)
random_word = mywordlist[random_number]
random_words.append(random_word)
print ("\n\n ", how_many, "random words from a list of", exclusive_range, "words:\n")
c = 0
for word in random_words:
c += 1
print('{:10d}'.format(c), word)
print ("")