-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_dictionary_attack.py
More file actions
59 lines (45 loc) · 1.59 KB
/
simple_dictionary_attack.py
File metadata and controls
59 lines (45 loc) · 1.59 KB
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
## libraries
import time
import hashlib
import pandas as pd
import random
class DictionaryAttack:
def __init__(self, password=str):
self.password = password
self.password_hash = hashlib.sha256(password.encode()).hexdigest()
self.success = "The password was found: "
self.fail = "The password could not be cracked "
def crack_password(self):
with open(
r"yourpath",
"r",
encoding="latin-1",
) as f:
words = f.read().split()
for word in words:
word_hash = hashlib.sha256(word.encode()).hexdigest()
if word_hash == self.password_hash:
return self.success + self.password
else:
return self.fail
if __name__ == "__main__":
password_difficult = "difficultpassword##!!?*?235465367453"
password_easy = "123456"
start_time_difficult = time.time()
attempt_result_difficult = DictionaryAttack(password_difficult).crack_password()
end_time_difficult = time.time()
total_time_elapsed_difficult = end_time_difficult - start_time_difficult
print(
attempt_result_difficult,
", The code ran: ",
"{0:.10f}".format(total_time_elapsed_difficult),
)
start_time_easy = time.time()
attempt_result_easy = DictionaryAttack(password_easy).crack_password()
end_time_easy = time.time()
total_time_elapsed_easy = end_time_easy - start_time_easy
print(
attempt_result_easy,
", The code ran: ",
"{0:.10f}".format(total_time_elapsed_easy),
)