-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaph
executable file
·54 lines (43 loc) · 1.3 KB
/
paph
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
#!/usr/bin/python3
import os
import random
import sys
def help():
print(
"""Usage :\n"""
"""paph -h shows this help\n"""
"""paph 5 generates a passphrase of 5 random words.\n"""
"""paph generates a passphrase of 6 random words.\n"""
"""As a 6 words long passphrase is recommended, """
"""this is the default value.\n""")
def wrong_args(arg):
print("Wrong arg. '%s' found" % arg)
help()
def no_dictfile(path):
print("No dict file named %s" % path)
def valid_word(word):
return len(set(word)) > 3
if __name__ == "__main__":
filename = "words_alpha.txt"
path = os.path.join(os.path.dirname(__file__), filename)
if not os.path.exists(path) or not os.path.isfile(path):
no_dictfile(path)
exit(1)
args = sys.argv
qty = 6
if len(args) > 1:
if args[1] == "-h":
help()
exit(0)
if not args[1].isdecimal():
wrong_args(args[1])
exit(1)
qty = int(args[1])
with open(path, "rb") as f:
random.seed()
words = [word.decode("latin-1") for word in f if valid_word(word)]
choices = [
random.choice(words).replace("\r", "").replace("\n", "") for
i in range(qty)]
print(" ".join(choices))
exit(0)