-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_generator.py
98 lines (74 loc) · 3.37 KB
/
password_generator.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
96
97
98
import secrets
def generate_password(length):
digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
lower_letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z']
upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y',
'Z']
special_chr = ['!', "@", "$"]
and_chr = ['&', ',', '/', ';', '.']
LETTER_LS = upper_letters + lower_letters + digits + special_chr
COMBINED_LS = upper_letters + lower_letters + special_chr + and_chr
password = ''
state = True
for x in range(length):
if state:
current_letter = secrets.choice(LETTER_LS)
password += current_letter
state = False
if current_letter in digits:
state = True
else:
password += secrets.choice(COMBINED_LS)
state = True
return password
def _upper_conv(word):
return word[0].upper() + word[1:]
def password_to_sentence(password):
subject_letters = {'a': 'astronaut', 'b': 'bumblebee', 'c': 'canary', 'd': 'dinosaur', 'e': 'elephant', 'f': 'fish', 'g': 'goat',
'h' : 'horse', 'i': 'iguana', 'j': 'joker', 'k': 'koala', 'l': 'lion', 'm': 'mouse', 'n': 'ninja', 'o': 'owl',
'p': 'panda', 'q': 'queen', 'r': 'rabbit', 's': 'snake', 't': 'tiger', 'u': 'unicorn', 'v': 'vulture',
'w': 'worm', 'x': 'xylophone', 'y': 'yak', 'z': 'zebra' }
verb_letters = {'a': 'accepts', 'b': 'blesses', 'c': 'challenges', 'd': 'delights', 'e': 'enjoys', 'f': 'fetches', 'g': 'guards',
'h' : 'handles', 'i': 'imagines', 'j': 'jokes', 'k': 'kicks', 'l': 'launches', 'm': 'manages', 'n': 'needs', 'o': 'observes',
'p': 'paints', 'q': 'questions', 'r': 'recognizes', 's': 'scratches', 't': 'ticks', 'u': 'uses', 'v': 'visits',
'w': 'weighs', 'x': 'x-rays', 'y': 'yells', 'z': 'zips'}
symbol_letters = {'!': 'i', '$':'s', '@' : 'a'}
and_chr = {'&': 'and', ',' :',', '/': '/', ';' :';', '.':'.'}
reverse_acroynm = []
state = 0
for letter in password:
if letter in and_chr:
reverse_acroynm.append(letter)
state = 0
elif letter in symbol_letters:
temp_letter = symbol_letters[letter]
if state ==0 or state == 2:
word = subject_letters[temp_letter]
else:
word = verb_letters[temp_letter]
state += 1
word = letter + word[1:]
reverse_acroynm.append(word)
elif letter.isdigit():
reverse_acroynm.append(letter)
elif state == 0 or state == 2:
word = subject_letters[letter.lower()]
if letter.isupper():
word = _upper_conv(word)
reverse_acroynm.append(word)
state += 1
elif state == 1:
word = verb_letters[letter.lower()]
if letter.isupper():
word = _upper_conv(word)
reverse_acroynm.append(word)
state += 1
if state == 3:
state = 0
return ' '.join(reverse_acroynm)
print(password_to_sentence(generate_password(10)))