-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharcenciel(test).py
309 lines (244 loc) · 11.3 KB
/
arcenciel(test).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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import hashlib
import os
import time
import time
import tkinter as tk
from tkinter import messagebox
#LES FONCTIONS DE REDUCTION
def reduce_hash_6_caracters(hashed_value):
return hashed_value[:6]
def reduce_hash_7_caracters(hashed_value):
return hashed_value[:7]
def reduce_hash_8_caracters(hashed_value):
return hashed_value[:8]
def reduce_hash_9_caracters(hashed_value):
return hashed_value[:9]
def reduce_hash_10_caracters(hashed_value):
return hashed_value[:10]
def reduce_hash_11_caracters(hashed_value):
return hashed_value[:11]
def reduce_hash_12_caracters(hashed_value):
return hashed_value[:12]
def hash_word(word):
hashed_word = hashlib.md5(word.encode()).hexdigest()
return hashed_word
def load_rainbow_table(filename):
"""Loads the rainbow table from a file."""
table = {}
with open(filename, 'r') as f:
for line in f:
word, hash_value = line.strip().split(',')
table[hash_value] = word
return table
def search_rainbow_table(hash_value, table):
"""Searches for a hash in the rainbow table."""
if hash_value in table:
return table[hash_value]
return None
def crack_password_6caracters(hash_value, table):
password = search_rainbow_table(hash_value, table)
if password:
print(password)
for j in range(1000):
word = hash_word(password)
# print(word)
password = reduce_hash_6_caracters(word)
# print(password)
return password
else:
for word, hash_value_table in table.items():
#print(hash_value_table)
hashed_word = hash_word(hash_value_table)
#print(hashed_word)
hashreduit = reduce_hash_6_caracters(hashed_word)
if hashreduit == hash_value:
return hash_value_table # <--- Return immediately when match found
for k in range(1000):
reduced_hash = reduce_hash_6_caracters(hashed_word)
# print(reduced_hash)
if reduced_hash == hash_value:
return motdepasse # <--- Return immediately when match found
hashed_word = hash_word(reduced_hash)
motdepasse=reduced_hash
# print(hashed_word)
return None
def crack_password_7caracters(hash_value, table):
password = search_rainbow_table(hash_value, table)
if password:
print(password)
for j in range(1000):
word = hash_word(password)
password = reduce_hash_7_caracters(word)
return password
else:
for word, hash_value_table in table.items():
hashed_word = hash_word(hash_value_table)
hashreduit = reduce_hash_7_caracters(hashed_word)
if hashreduit == hash_value:
return hash_value_table
for k in range(1000):
reduced_hash = reduce_hash_7_caracters(hashed_word)
if reduced_hash == hash_value:
return motdepasse
hashed_word = hash_word(reduced_hash)
motdepasse=reduced_hash
return None
def crack_password_8caracters(hash_value, table):
password = search_rainbow_table(hash_value, table)
if password:
print(password)
for j in range(1000):
word = hash_word(password)
password = reduce_hash_8_caracters(word)
return password
else:
for word, hash_value_table in table.items():
hashed_word = hash_word(hash_value_table)
hashreduit = reduce_hash_8_caracters(hashed_word)
if hashreduit == hash_value:
return hash_value_table
for k in range(1000):
reduced_hash = reduce_hash_8_caracters(hashed_word)
if reduced_hash == hash_value:
return motdepasse
hashed_word = hash_word(reduced_hash)
motdepasse=reduced_hash
return None
def crack_password_9caracters(hash_value, table):
password = search_rainbow_table(hash_value, table)
if password:
print(password)
for j in range(1000):
word = hash_word(password)
password = reduce_hash_9_caracters(word)
return password
else:
for word, hash_value_table in table.items():
hashed_word = hash_word(hash_value_table)
hashreduit = reduce_hash_9_caracters(hashed_word)
if hashreduit == hash_value:
return hash_value_table
for k in range(1000):
reduced_hash = reduce_hash_9_caracters(hashed_word)
if reduced_hash == hash_value:
return motdepasse
hashed_word = hash_word(reduced_hash)
motdepasse=reduced_hash
return None
def crack_password_10caracters(hash_value, table):
password = search_rainbow_table(hash_value, table)
if password:
print(password)
for j in range(1000):
word = hash_word(password)
password = reduce_hash_10_caracters(word)
return password
else:
for word, hash_value_table in table.items():
hashed_word = hash_word(hash_value_table)
hashreduit = reduce_hash_10_caracters(hashed_word)
if hashreduit == hash_value:
return hash_value_table
for k in range(1000):
reduced_hash = reduce_hash_10_caracters(hashed_word)
if reduced_hash == hash_value:
return motdepasse
hashed_word = hash_word(reduced_hash)
motdepasse=reduced_hash
return None
def crack_password_11caracters(hash_value, table):
password = search_rainbow_table(hash_value, table)
if password:
print(password)
for j in range(1000):
word = hash_word(password)
password = reduce_hash_11_caracters(word)
return password
else:
for word, hash_value_table in table.items():
hashed_word = hash_word(hash_value_table)
hashreduit = reduce_hash_11_caracters(hashed_word)
if hashreduit == hash_value:
return hash_value_table
for k in range(1000):
reduced_hash = reduce_hash_11_caracters(hashed_word)
if reduced_hash == hash_value:
return motdepasse
hashed_word = hash_word(reduced_hash)
motdepasse=reduced_hash
return None
def crack_password_12caracters(hash_value, table):
password = search_rainbow_table(hash_value, table)
if password:
print(password)
for j in range(1000):
word = hash_word(password)
password = reduce_hash_12_caracters(word)
return password
else:
for word, hash_value_table in table.items():
hashed_word = hash_word(hash_value_table)
hashreduit = reduce_hash_12_caracters(hashed_word)
if hashreduit == hash_value:
return hash_value_table
for k in range(1000):
reduced_hash = reduce_hash_12_caracters(hashed_word)
if reduced_hash == hash_value:
return motdepasse
hashed_word = hash_word(reduced_hash)
motdepasse=reduced_hash
return None
def main(hash_value, label):
start_time = time.time()
filename = "rainbow_table(6_caracteres).txt"
table = load_rainbow_table(filename)
reduced_hash_value = reduce_hash_6_caracters(hash_value)
password = crack_password_6caracters(reduced_hash_value, table)
if (password == None):
filename = "rainbow_table(7_caracteres).txt"
table = load_rainbow_table(filename)
reduced_hash_value = reduce_hash_7_caracters(hash_value)
password = crack_password_7caracters(reduced_hash_value, table)
if (password == None):
filename = "rainbow_table(8_caracteres).txt"
table = load_rainbow_table(filename)
reduced_hash_value = reduce_hash_8_caracters(hash_value)
password = crack_password_8caracters(reduced_hash_value, table)
if (password == None):
filename = "rainbow_table(9_caracteres).txt"
table = load_rainbow_table(filename)
reduced_hash_value = reduce_hash_9_caracters(hash_value)
password = crack_password_9caracters(reduced_hash_value, table)
if (password == None):
filename = "rainbow_table(10_caracteres).txt"
table = load_rainbow_table(filename)
reduced_hash_value = reduce_hash_10_caracters(hash_value)
password = crack_password_10caracters(reduced_hash_value, table)
if (password == None):
filename = "rainbow_table(11_caracteres).txt"
table = load_rainbow_table(filename)
reduced_hash_value = reduce_hash_11_caracters(hash_value)
password = crack_password_11caracters(reduced_hash_value, table)
if (password == None):
filename = "rainbow_table(12_caracteres).txt"
table = load_rainbow_table(filename)
reduced_hash_value = reduce_hash_12_caracters(hash_value)
password = crack_password_12caracters(reduced_hash_value, table)
elapsed_time = time.time() - start_time
if password:
label.config(text=f"Password found: {password}\nSearch time: {elapsed_time:.4f} seconds")
else:
label.config(text=f"Password not found in rainbow table.\n")
def gui():
root = tk.Tk()
root.title("Attaque Arc en ciel")
tk.Label(root, text="Enter hash value:").pack()
hash_value = tk.Entry(root, width=50, borderwidth=3)
hash_value.pack()
button = tk.Button(root, text="Crack Password", command=lambda: main(hash_value.get(), label))
button.pack()
label = tk.Label(root, text="", font=("Arial", 18), fg="black")
label.pack()
root.mainloop()
if __name__ == "__main__":
gui()