-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
177 lines (143 loc) · 4.76 KB
/
main.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
#!/usr/bin/env python3
import sys
import os.path
def open_file(file_path):
array = []
f = open(file_path, "r")
for i in f:
array.append(i.strip())
return array
def write_file(file_path, word_list):
f = open(file_path, "w")
for word in word_list:
f.write(word + "\n")
def merge_file(file_path, word_list):
f = open(file_path, "a")
for word in word_list:
f.write(word + "\n")
# number = the number of digit
def add_number(word_list, digit):
new_word_list = []
if word_list == []:
for number in range(0, (10 ** digit)):
new_word_list.append(str(number))
else:
for word in word_list:
# new_word_list.append(word)
for number in range(0, (10 ** digit)):
new_word_list.append(word + str(number))
return new_word_list
def add_special_characters(word_list):
new_word_list = []
special_characters_tab = ["#", "@", "!", "?", "-", "_", "<", ">", ';', ':', ',', '/', "\\", " "]
for word in word_list:
# new_word_list.append(word)
for char in special_characters_tab:
new_word_list.append(word + char)
return new_word_list
def print_tab(word_list):
write_file("result.txt", word_list)
for i in word_list:
print(i, end="\t")
print("\n#" + str(len(word_list)))
# make every combinaison of list1+list2
def mix_list(list1, list2):
l3 = []
for l1 in list1:
for l2 in list2:
l3.append(l1 + l2)
return l3
# command = the order for the wordlist
# # = word
# * = digit
# @ = special characters
# Example : "#@****" = for each word in the word list add a special character and four digit
def command(word_list, command):
digi_tab = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
special_characters_tab = ["#", "@", "!", "?", "-", "_", "<", ">", ';', ':', ',', '/', "\\", " "]
new_word_list = []
bool = -1
for index in range(len(command)):
char = command[index]
if char == "#":
if new_word_list == []:
new_word_list = word_list
else:
new_word_list = mix_list(new_word_list, word_list)
if char == "*":
if new_word_list == []:
new_word_list = digi_tab
else:
new_word_list = add_number(new_word_list, 1)
if char == "@":
if new_word_list == []:
new_word_list = special_characters_tab
else:
new_word_list = add_special_characters(new_word_list)
return new_word_list
def add_tranformation(word_list):
new_word_list = []
transformations = [
{'a': ['@', '4', 'A']},
{'b': '8'},
{'e': ['3', 'E']},
{'g': ['9', '6']},
{'i': ['1', '!']},
{'o': '0'},
{'s': ['$', '5']},
{'t': '7'}
]
check = 0
for word in word_list:
new_word_list.append(word)
for item in transformations:
for key in item:
for elem in item[key]:
x = word.replace(key, elem, 1)
if x not in word_list and x not in new_word_list:
check = 1
new_word_list.append(x)
if check == 1:
temp = add_tranformation(new_word_list)
return temp
else:
return word_list
def steps():
tab = open_file("file.txt")
# tab = command(tab, "#@")
# tab = add_special_characters(tab)
# tab = add_number(tab, 2')
tab = add_tranformation(tab)
# print_tab(tab)
write_file("result.txt", tab)
def print_help():
print("Utilisation : ./main.py [_input.txt] [OPTIONS]")
print("\t -c 'COMMAND': Appliquer la commande COMMAND a la liste de mot")
print("\t -t : transformation des mots de la liste")
print("\t -o file.txt : export la liste de mot dans file.txt")
print("-------")
print("Utilisation des commandes\n# = word\n* = digit\n@ = special characters\nExample : '#@****' = for each word in the word list add a special character and four digit")
def main(argv):
if len(argv) == 1:
print_help()
if len(argv) > 2:
if os.path.isfile(argv[1]):
tab = open_file(argv[1])
else:
print("error give a valid name")
return 0
if '-t' in argv:
tab = add_tranformation(tab)
if '-c' in argv:
index = sys.argv.index('-c')
if index + 1 <= len(argv):
tab = command(tab, argv[index + 1])
if '-o' in argv:
index = sys.argv.index('-o')
if index + 1 <= len(argv):
write_file(argv[index + 1], tab)
if '-no_print' not in argv:
print_tab(tab)
if __name__ == '__main__':
# steps()
main(sys.argv)