-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdyceware
More file actions
executable file
·54 lines (41 loc) · 1.18 KB
/
dyceware
File metadata and controls
executable file
·54 lines (41 loc) · 1.18 KB
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/env python3
"""
USAGE: dyceware [wordlist file] [OPTIONS]
DESCRIPTION:
Generate a diceware passphrase. This requires a diceware wordlist.
You can download one from the EFF[0].
[0]: https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt
-n
Wordcount of diceware passphrase.
-j
Join diceware passphrase words together. Default False.
"""
import sys
import random
def main():
"""Generate a diceware passphrase."""
delimiter = ' '
wordcount = 10
try:
args = iter(sys.argv[1:])
for arg in args:
if arg == '-j':
delimiter = ''
elif arg == '-n':
wordcount = int(next(args))
else:
raise ValueError
except (IndexError, ValueError):
print(__doc__)
sys.exit(1)
with open('wordlist.txt') as f:
wordlist = dict([
line.split() for line in f.readlines()
])
phrase = []
for _ in range(wordcount):
key = ''.join([str(random.randrange(1, 7)) for _ in range(5)])
phrase.append(wordlist[key])
print(delimiter.join(phrase), end='')
if __name__ == '__main__':
main()