Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a password cracker program for the passwords created according to the policy outlined in assignment 15 (exactly 8 characters: 5 letters and 3 digits).
Write a password cracker program for the passwords created according to the policy outlined in assignment 15 (exactly 8 characters: 5 letters and 3 digits). You are to write a function that takes one parameter that is a hash of a password and should return a possible password (a string) that has the same hash. Use python secure hash function sha1 from hashlib module. Hint: The brute force method will be more than adequate to the task. This program doesn't print anything, I don't know what's wrong please help!
import hashlib def get_password(password_hash): password = [0, 0, 0, 0, 0, 0, 0, 0] # create a password array of size 8 possible_letters - "abcdefghijklmnopqrstuvwxy ZABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" for chi in possible_letters: password[] = chi for ch2 in possible_letters: password[1] = ch2 for ch3 in possible_letters: password[2] = ch3 for ch4 in possible_letters: password [3] = ch4 for ch5 in possible_letters: password[4] = ch5 for ch6 in possible_letters: password[5] = ch6 for ch7 in possible_letters: password[6] = ch7 for ch8 in possible_letters: password[7] = ch8 # convert array into string string = "" string = string + password[i] # create a hash for the string string_hash = hashlib.sha1(string.encode() # now compare string hash and password hash if string_hash.digest() == password_hash.digest(): # return the string as it is the password return string def main(): password = "aR3fg570" password_hash = hashlib.shal(password. encode()) cracked_password = get_password(password_hash) print(cracked_password) - if __name__ == '__main_': main()Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started