Python Dictionary-based Password Cracker
At this point, you should be able to write basic Python programs that incorporate:
- data types (strings, integers, booleans, lists, and dictionaries)
- variables
- comparisons
- control flow (
if/elif/else) - functions
- important libraries
Putting together all of these "ingredients" to create a "recipe" can be challenging. In this exercise, you will combine these concepts to create a password-cracking program.
Learning Objectives
You should be able to:
- Create a simple Python password-cracking script.
Video Walkthrough
Use this video to follow along with the steps in this lab.
Python Password Cracker
You will create a program that will crack passwords using a dictionary attack.
- The password hash you need to crack is: 308738b8195da46d65c96f4ee3909032e27c818d8a079bccb5a1ef62e8daaa45
- The password hash is SHA256.
- The password is the name of a sport.
Required: Put your first and last name as one of the elements in the dictionary. I.e., the dictionary will contain a list of sports and your name.
The following hints will help you write your program.
- Import the hashing library
- Store a list of sports in a variable. Add your name to the list of sports.
- Store the target hash as a variable.
- Create a loop that goes through each sport in your list.
- Calculate the SHA256 hash of each sport.
- Compare the resulting hash of the sport with the target.
- If they match, you've cracked the password.
- Write output that summarizes whether you cracked the password or not.
There are two main ways that the script may fail to crack the password:
- There are bugs in the code.
- Your dictionary does not contain the target password. Try adding more items to your dictionary.
Reflection
- Which elements of the assignment were most challenging?
- What improvements would you make to your code?
- How would you code a brute-force attack?