-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassGenerator.py
115 lines (95 loc) · 3.71 KB
/
passGenerator.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import itertools as it
import time
import os
start_time = time.time()
infos = {"Name": "null", "Surname": "null", "Birthday": "null"}
def saveToTxt(liste: list, filepath: str, filename: str):
"""Save a list to a txt file
Args:
liste (list): list to be exported
filepath (str): filepath of where you want the list to be saved
filename (str): name of the file
"""
with open(filepath + filename + ".txt", "w") as outfile:
outfile.write("\n".join(liste))
print(f"Passwords successfully exported to : {filepath}{filename}.txt")
def askInfos(liste: dict):
"""Ask all infos to the user
Args:
liste (dict): dictionnary containing the wanted infos
"""
for info in liste:
if info == "Birthday":
givenInfo = input(f"Enter info : {info} (DD/MM/YYYY)\n")
else:
givenInfo = input(f"Enter info : {info}\n")
if not givenInfo == '':
liste[info] = givenInfo
def allStrings(string: str):
"""Generate a list of upper and lower possibility of a given string
Args:
string (str): given string
Returns:
(list): list of all generated strings
"""
lu_sequence = ((c.lower(), c.upper()) for c in string)
return [''.join(x) for x in it.product(*lu_sequence)]
def birthdaySeparator(birthday: str):
"""Seperate infos from a birthday string
Args:
birthday (str): birthday string
Returns:
(list): day, month and year of birth
"""
if len(birthday) == 10:
day = birthday[0:2]
month = birthday[3:5]
year = birthday[6:10]
return day, month, year
return "null"
def passwords(infos: dict):
"""Generate passwords from the given infos
Args:
infos (dict): dictionnary containing the infos
Returns:
passwordsList (list): list containing the passwords
"""
passwordsList = []
for info in infos:
if not infos[info] == "null":
if not info == "Birthday":
for x in range(len(allStrings(infos[info]))):
passwordsList.append(allStrings(infos[info])[x])
else:
# Name + Surname & Surname + Name
for noms in allStrings(infos["Name"]):
for prenom in allStrings(infos["Surname"]):
nomprenom = noms + prenom
prenomnom = prenom + noms
passwordsList.append(prenomnom)
passwordsList.append(nomprenom)
# Name + birthday
for noms in allStrings(infos["Name"]):
noms = noms + birthdaySeparator(infos[info])[2]
passwordsList.append(noms)
# Surname + birthday
for prenom in allStrings(infos["Surname"]):
prenom = prenom + birthdaySeparator(infos[info])[2]
passwordsList.append(prenom)
return passwordsList
print("""
____ ____ ____ ______
/ __ \/ _/ / __ \____ ___________/ ____/__ ____
/ /_/ // /_____/ /_/ / __ `/ ___/ ___/ / __/ _ \/ __ \\
/ ____// /_____/ ____/ /_/ (__ |__ ) /_/ / __/ / / /
/_/ /___/ /_/ \__,_/____/____/\____/\___/_/ /_/
""")
askInfos(infos)
filename = input("Enter name of the output file:\n")
path = ''
if os.name == "nt":
path = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop') + "\\passLists\\"
if not os.path.exists(path):
os.makedirs(path)
saveToTxt(passwords(infos), path, filename)
print(f'\nTotal time: {time.time() - start_time} seconds')