-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash:password:algorithm
More file actions
48 lines (37 loc) · 1.74 KB
/
hash:password:algorithm
File metadata and controls
48 lines (37 loc) · 1.74 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
# Script to save the cracked passwords along with their hash values to an output file.
# Each line in the output file will be in the format hash:password:algorithm.
import hashlib
def sha256_hash(password):
"""Generate SHA256 hash for a given password."""
return hashlib.sha256(password.encode()).hexdigest()
def dictionary_attack(hashes, common_passwords):
"""Attempt to crack the hashes using dictionary attack."""
cracked_passwords = {}
for password in common_passwords:
hashed_password = sha256_hash(password)
for h in hashes:
if h == hashed_password:
cracked_passwords[h] = password
return cracked_passwords
def load_from_file(filename):
"""Load lines from a given file."""
with open(filename, 'r') as file:
return [line.strip() for line in file]
def save_to_file(filename, cracked):
"""Save cracked passwords and hashes to a file."""
with open(filename, 'w') as file:
for hash_value, password in cracked.items():
file.write(f"{hash_value}:{password}:SHA256\n")
if __name__ == "__main__":
# Accept file names as input
password_file = input("Enter the file name containing the common passwords: ")
hash_file = input("Enter the file name containing the hashes: ")
output_file = input("Enter the file name to save the cracked passwords: ")
# Load common passwords and hashes from the files
COMMON_PASSWORDS = load_from_file(password_file)
hashes_to_crack = load_from_file(hash_file)
# Perform dictionary attack
cracked = dictionary_attack(hashes_to_crack, COMMON_PASSWORDS)
# Save cracked passwords to the output file
save_to_file(output_file, cracked)
print(f"Cracked passwords saved to {output_file}")