-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import itertools # (Educative, n.d.) | ||
|
||
def generate_pass_attempts(minimum_length, maximum_length, characters): | ||
for length in range(minimum_length, maximum_length + 1): | ||
for combination in itertools.product(characters, repeat=length): | ||
pass_attempt = "".join(combination) | ||
yield pass_attempt | ||
|
||
# This will ask for the amount of hashes that the user wants to enter | ||
def hash_user(): | ||
hash_num = int(input("Enter the number of hashes you would like to enter: ")) | ||
|
||
# This line starts an list that is empty in order to store passwords and the hashes | ||
hashes = [] | ||
|
||
# This line will collect the hashes from the user | ||
for x in range(hash_num): | ||
value_hash = input("Please enter the value of hash {}: ".format(x + 1)) | ||
password = input("Please enter the corresponding password: ") | ||
hashes.append((value_hash, password)) | ||
|
||
# This reads the hashes and the corresponding passwords from the csv file | ||
# Also changes the file path and indices for the columns correctly | ||
import csv # (Python, 2023) | ||
csv_file = "sha256_hashes.csv" | ||
with open(csv_file, "r") as file: | ||
reader = csv.reader(file) | ||
for row in reader: | ||
value_hash = row[0] | ||
password = row[1] | ||
hashes.append((value_hash, password)) | ||
|
||
# This part is the brute force to crack the hashes | ||
characters = "abcdefjhijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*_+=~':;,.()_/£¬`€" | ||
maximum_length = 6 | ||
minimum_length = 1 | ||
|
||
maximum_attempts = 100000000000 | ||
|
||
# This part gives me the time taken in order for the process to finish | ||
import time # (Create a Timer in Python: Elapsed Time, Decorators, and More – LearnDataSci, n.d.) | ||
start_time = time.time() | ||
end_time = start_time | ||
|
||
for value_hash, password in hashes: | ||
cracked_value = None | ||
attempts = 0 | ||
|
||
pass_attempts = generate_pass_attempts(minimum_length, maximum_length, characters) | ||
|
||
for pass_attempt in pass_attempts: | ||
attempts += 1 | ||
|
||
# Uses SHA256 in order to hash the password | ||
import hashlib # (Hashlib — Secure Hashes and Message Digests, n.d.) | ||
hashed_password = hashlib.sha256(pass_attempt.encode()).hexdigest() | ||
|
||
# This section compares the targeted hash with the one that has been generated | ||
if hashed_password == value_hash: | ||
cracked_value = pass_attempt | ||
break | ||
|
||
if attempts >= maximum_attempts or time.time() >= end_time: | ||
break | ||
|
||
# This part tells the user if the brute force was successful or not, by printing out a message to let the user know if they were successful or unsuccessful | ||
if cracked_value: | ||
print("Hash Value:", value_hash, "Password:", password, "Cracked Value:", cracked_value) | ||
else: | ||
print("Hash:", value_hash, "Password:", password, "The cracking failed using the maximum attempts given") | ||
|
||
# This prints a message to tell the user the amount of time taken in seconds for the code to finish | ||
elapsed_time = time.time() - start_time # (Create a Timer in Python: Elapsed Time, Decorators, and More – LearnDataSci, n.d.) | ||
print("The amount of time taken:", elapsed_time, "Seconds") | ||
|
||
# This calls for the hash_user function in order to start the program | ||
hash_user() |
Empty file.