forked from fineanmol/Hacktoberfest2024
-
Notifications
You must be signed in to change notification settings - Fork 0
/
password generator.py
169 lines (157 loc) · 5.98 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
## UPDATE 2021 : Thought of changing this with better variables and optimizations
## but left it as it is , as a memoir for old *Me Coder*
# import all the necesary libraries
import os
import shutil
import math
import itertools
# the welcome function to be displayed at the beginning of the file
def welcome():
# usig ascii color code
print("\033[40m")
print("\t\t\033[91m PyForCe")
print("\n\n\t\t\033[92m An \"Intelligent\" Dictionary Creation Tool")
print("\n\n\t\t\033[96m V1.0")
def calculateBytes(x,r):
bytes = x * (r + 1)
# dividing bytes by 1000 to get kb
# kbs = bytes / 1000
# print("Calculated Size in kbs : ",kbs)
return bytes
def sizeOnhardDisk(freekb):
# size_on_disk = 0
if freekb < 4096:
sze = 1
else:
sze = round((freekb / 4096), 1)
szplit = str(sze).split(".")
sze = int(sze)
if int(szplit[1]) > 0:
sze = sze + 1
size_on_disk = ((sze * 4096) // 1000)
return size_on_disk
# math function to calculate nCr
def nCr(n,r):
f = math.factorial
x = f(n) / f(r) / f(n-r)
return x
# the actual function that crates combinations
def createcombs(words,i):
global f
# pass the string to be combined and length of password
for c in itertools.combinations(words,i):
t = "".join(c)
f.write(t + "\n")
# print(t)
# the function to check for available and empty disk space
def checkdiskspace(passfilelength):
# returns a tuple
total, used, free = shutil.disk_usage("/")
# calculate the size in gigabits
freeGb = (free // (2**30)) - 1
pass_file_length_GB = (((passfilelength // 1024) // 1024) // 1024)
# just log codes
# print(freeGb," GB")
# print("length of pass file ", pass_file_length_GB, " GB")
# print(freeGb)
# print(pass_file_length_GB)
if freeGb - pass_file_length_GB > 1:
print(" \n\nEnough Available Disk Space\n Creating Password Dictionary...")
else:
print("\033[91m Your Device Doesn't Have Enough Disk Space..\n Quitting...")
# code to reset the color changes
print("\033[0m")
exit(0)
# the function to check for valid Characters
# feel free to add or remove characters as per requirements
# if you don't want to check go to the main function and disable the function call
def checkForCharacters(kword):
chars = "!@#$%^&*()_+-=?></\"';|~`,'"
for k in kword:
if k in chars:
print("\033[91m Alert Invalid Characters Found")
# code to reset the color changes
print("\033[0m")
# any special charcter found
# need to exit the code
return False
else:
pass
# print("ok")
return True
# start the execution
# only if this file is executed
if __name__ == "__main__":
global f
# clear the console according to the OS
# didn't check it on windows yet
# :p
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
# call the welcome function to show the welcome screen
welcome()
kwords = input("\n\n\033[34m Enter Keywords Related To victim Seperated By Commas \n > ")
klist = kwords.split(",")
kwords = "".join(klist)
# to change the minimum length change the value here
if len(kwords) <= 7:
# to less characters to create combinations
print("\033[91m Too Less Characters...")
# code to reset the color changes
print("\033[0m")
# hence exit
exit(0)
if checkForCharacters(kwords):
# every char is valid
# ask the length of password
password_Length = input("\n\n\033[34m Enter Password Length\n For More Values Seperate Them By Spaces > ")
# re assign the values to password_Length but as a list seperated
password_Length = password_Length.split(" ")
# check the list for any value to be less than 6 and greater than 12
# you can change the values in the loop below to achieve your desired length
# assuming that you will not flood the list with unneed values
# no checking for length or for duplicate values in the list
# -----
# converting the values of list (password_Length) to string
for i in range(0, len(password_Length)):
try:
password_Length[i] = int(password_Length[i])
except ValueError:
print("\033[91m Invalid Characters Found For \"Password Length\"")
# code to reset the color changes
print("\033[0m")
exit(0)
# after successfuly converting the values of list to integer
# check if each value is less than 12 and greater than 6
for i in password_Length:
if int(i) < 6 or int(i) > 12:
print("\033[91m Enter Password Length To be less Than 12 And greater Than 6..")
# code to reset the color changes
print("\033[0m")
exit(0)
# now check for the no of possible combinations
temp = 0
tempkb = 0
for i in password_Length:
x = nCr(len(kwords), i)
kbs = calculateBytes(x,i)
temp = temp + x
tempkb = tempkb + kbs
# print(tempkb)
tempkb = int(tempkb)
print("\033[33m\n\n",int(temp)," Possible Items")
print("\033[33m Size It Will Take On HardDisk is ", sizeOnhardDisk(int(tempkb)), " Kb")
choice = input("\033[33m Would You Like To Continue (y/n) : ")
if choice == "y":
# createcombs(kwords)
checkdiskspace(tempkb)
f = open("passwords.txt", "w")
for i in password_Length:
createcombs(kwords,i)
print(" Created..")
# code to reset the color changes
print("\033[0m")
else:
exit(0)