-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConverter.py
177 lines (156 loc) · 5.57 KB
/
Converter.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
170
171
172
173
174
175
176
177
print("""
__ __ _ _ _ _ ____ _
\ \ / / ___ _ __ __| || | (_) ___ | |_ / ___| ___ _ __ __ __ ___ _ __ | |_ ___ _ __
\ \ /\ / / / _ \ | '__| / _` || | | |/ __|| __| | | / _ \ | '_ \ \ \ / / / _ \| '__|| __| / _ \| '__|
\ V V / | (_) || | | (_| || |___ | |\__ \| |_ | |___ | (_) || | | | \ V / | __/| | | |_ | __/| |
\_/\_/ \___/ |_| \__,_||_____||_||___/ \__| \____| \___/ |_| |_| \_/ \___||_| \__| \___||_|
""")
# By Nandan R
# Date: 27/03/2024
# Version 3.0
mode = input("Would you like to use the simple mode or Expert mode? (S/E): ")
print()
mode = mode.upper()
wordlist = input("Enter the wordlist Filename (.TXT): ")
if wordlist.endswith(".txt"):
pass
else:
wordlist = wordlist + ".txt"
print()
output = input("Enter the output Filename (.TXT): ")
if output.endswith(".txt"):
pass
else:
output = output + ".txt"
print()
output = output.lower()
if mode == "S":
print(f"Converting {wordlist} to {output}")
try:
with open(wordlist, "r") as f:
with open(output,"w") as w:
lines = f.readlines()
for line in lines:
w.write("STRING " + line + "\n")
w.write("ENTER" + "\n")
except FileNotFoundError:
print("File Not Found")
exit()
except EndOfFileError:
pass
except Exception as e:
print(f"An Error Occured: {e}")
exit()
print(f"Conversion Completed Check the output file @ {output}")
def delaymode():
global delay, delay_time
delay = input("Would you like to add a delay? (Y/N): ")
delay = delay.upper()
if delay == "Y":
delay = True
delay_time = input("Enter the delay time (in seconds): ")
elif delay == "N":
delay = False
delay_time = 0
def duplicatemode():
duplicate = input("Would you like to remove duplicates? (Y/N): ")
duplicate = duplicate.upper()
print()
if duplicate == "Y":
with open (wordlist, "r") as read:
lines = read.readlines()
lc={}
for line in lines:
if line in lc:
lc[line]+=1
else:
lc[line]=1
with open (wordlist, "w") as write:
for line in lc:
write.write(line)
def alternatemode():
global case, casechoice, convert
convert = []
case = input("Would you like to convert the wordlist to Alternate Case? (Y/N): ")
case = case.upper()
if case == "Y":
casechoice = input("Would you like to configure it (Y/N): ")
casechoice = casechoice.upper()
if casechoice == "Y":
casechoice = True
title= input("Would you like to convert the wordlist to Title Case? (Y/N): ")
title = title.upper()
if title == "Y":
convert += "T"
upper = input("Would you like to convert the wordlist to Uppercase? (Y/N): ")
upper = upper.upper()
if upper == "Y":
convert += "U"
lower = input("Would you like to convert the wordlist to Lowercase? (Y/N): ")
lower = lower.upper()
if lower == "Y":
convert += "L"
elif casechoice == "N":
convert = ["T"]
Converter()
def Converter():
for i in convert:
if i == "T":
with open(wordlist, "r") as f:
lines = f.readlines()
with open(wordlist, "a") as w:
for line in lines:
w.write(line.title())
elif i == "U":
with open(wordlist, "r") as f:
lines = f.readlines()
with open(wordlist, "a") as w:
for line in lines:
w.write(line.upper())
elif i == "L":
with open(wordlist, "r") as f:
lines = f.readlines()
with open(wordlist, "a") as w:
for line in lines:
w.write(line.lower())
def length():
global wordlength, lengthchoice
wordlength = input("Would you like to remove words outside of the wordlength limit? (Y/N): ")
wordlength = wordlength.upper()
if wordlength == "Y":
lengthchoice = input("Enter the length limit: ")
with open(wordlist, "r") as f:
lines = f.readlines()
with open(wordlist, "w") as w:
for line in lines:
line = line.strip()
if len(line) <= int(lengthchoice):
w.write(line + "\n")
if mode == "E":
delaymode()
length()
alternatemode()
duplicatemode()
print()
print(f"Converting {wordlist} to {output} with delay set to {delay}.")
try:
with open(wordlist, "r") as f:
with open(output,"w") as w:
lines = f.readlines()
for line in lines:
w.write("STRING " + line + "\n")
w.write("ENTER" + "\n")
if delay:
w.write("DELAY " + delay_time + "\n")
except FileNotFoundError:
print("File Not Found")
exit()
except EndOfFileError:
pass
except Exception as e:
print(f"An Error Occured: {e}")
exit()
print(f"Conversion Completed Check the output file @ {output}")
else:
print("Invalid Mode")
exit()