Skip to content
Advertisement

Hack with Rainbow method: getting the KeyError

I’m trying to find some passwords using the Rainbow method. I have a CSV file containing people’s names and their hashed passwords using SHA-256. I have to retrieve the original passwords which are four-digit numbers [1000-9999].

The CSV file:

JavaScript

My code:

JavaScript

When I run the code, following error appears:

JavaScript

As I know, this error appears when the dictionary I try to call doesn’t have that specific key. Since I’ve hashed every number between 1000 and 9999, dict2 has to contain the above key. Why do I get this error, and how can I solve it?

Advertisement

Answer

hashlib.sha256(str(i).encode('utf-8')) returns a HASH object, not the hex hash, so you are keying by object. Instead, you want to use the hexdigest() method to get the hex hash e.g. hashed_password = hashlib.sha256(str(i).encode('utf-8')).hexdigest().

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement