-
Notifications
You must be signed in to change notification settings - Fork 2
/
dicewarez.py
62 lines (43 loc) · 1.3 KB
/
dicewarez.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
import os, re
from random import randint, shuffle
from sys import exit
DICEWARE_LIST = {}
DICEWARE_LIST_PATH = "diceware.wordlist.asc.txt"
CUSTOM_LIST_PATH = "custom.wordlist.txt"
def setup():
ROLLS = []
WORDS = []
with open(DICEWARE_LIST_PATH, 'rb') as D:
for line in D.readlines():
line = re.findall(r'(\d{5})\s*(.*)', line.strip())[0]
ROLLS.append(str(line[0]))
WORDS.append(line[1])
shuffle(WORDS)
if os.path.exists(CUSTOM_LIST_PATH):
with open(CUSTOM_LIST_PATH, 'rb') as D:
CUSTOM_WORDS = [c.strip() for c in D.readlines() if len(c.strip()) >= 2]
WORDS = WORDS[:-(len(CUSTOM_WORDS))]
WORDS.extend(CUSTOM_WORDS)
shuffle(WORDS)
for i, r in enumerate(ROLLS):
DICEWARE_LIST[r] = WORDS[i]
def roll(num_dice, roll_range=[1,6]):
return "".join([str(randint(*roll_range)) for r in xrange(num_dice)])
def generate_passphrase(num_words=8):
return " ".join([DICEWARE_LIST[roll(5)] for r in xrange(num_words)])
if __name__ == "__main__":
pad_len = 20
os.system('clear')
setup()
print "Diceware!\n\n"
while True:
try:
if raw_input("press enter to generate credentials") == '':
print "\nOK, how about:\n"
print "%s\n" % ("*" * pad_len)
print generate_passphrase()
print "\n%s" % ("*" * pad_len)
print "\n"
except KeyboardInterrupt as e:
break
exit(0)