Python – How do I hash a string in Python?

How do I hash a string in Python?… here is a solution to the problem.

How do I hash a string in Python?

My code can output all possible combinations of characters in a given list of characters as follows:

def charList():
    charSet = string.ascii_letters + string.digits
    for wordchars in product(charSet, repeat=8):

Now I need to convert the output string to a DES hash and then compare the output to the user input to see if any matches are found.

There has been

some research and not much progress has been made. So wondering if there is anyone here who can help?


If you want to hash strings (instead of encrypting them), you can use the built-in hashlib module:

>>> import hashlib
>>> m = hashlib.md5()
>>> m.update("Nobody inspects")
>>> m.update(" the spammish repetition")
>>> m.digest()

EDIT: As mentioned in the comment, prefer hashlib.sha256() which is much safer today.

Related Problems and Solutions