-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaster_dictionary_attack.py
More file actions
72 lines (53 loc) · 1.89 KB
/
faster_dictionary_attack.py
File metadata and controls
72 lines (53 loc) · 1.89 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
60
61
62
63
64
65
66
67
68
69
70
71
72
## libraries
import time
import hashlib
import pandas as pd
import random
class dictionary_attack:
def __init__(self, path=str):
self.file_path = file_path
self.df = self.hash_table(file_path)
self.success = "The password was found: "
self.fail = "The password could not be cracked "
def hash_table(self, path):
df = pd.read_csv(
path,
delimiter="\n",
header=None,
names=["Passwords"],
encoding="ISO-8859-1",
)
def sha_encode(x):
return hashlib.sha256(x.encode()).hexdigest()
df["Hash"] = df["Passwords"].astype(str).apply(sha_encode)
return df
def crack_password(self, password):
password_hash = hashlib.sha256(password.encode()).hexdigest()
solution = self.df.loc[self.df["Hash"] == password_hash]
if solution.empty:
return self.fail
else:
return self.success + password
if __name__ == "__main__":
difficult_password = "difficultpassword##!!?*?235465367453"
easy_password = "123456"
file_path = r"C:\Users\Nutzer\Desktop\Projects\DictionaryAttack\rockyou.txt"
attack = DictionaryAttack(file_path)
start_time_difficult = time.time()
attempt_result_difficult = attack.crack_password(difficult_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 = attack.crack_password(easy_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),
)