Why won't this python hashing program work?

2018 views python
6

I just made a program where any text you put will spit back a text that is hashed. However, the program doesn't print the non-hashed text and then doesn't hash the real text. Any help would be greatly appreciated. Thanks

import hashlib

not_hashed = []
hashed = []
while True:
    word_hash = input("Hello this is a python string convertor.\nAny thing you say will be encoded using hashes\nWhat is your message: ")
    hashed.append(word_hash)
    hash_object = hashlib.md5(word_hash.encode())
    hashed.append(hash_object)
    print("This is your message")
    print("Not hashed: ")
    print(not_hashed)
    print("Hashed")
    print(hashed)

:)

answered question

Is hashed.append(word_hash) supposed to be not_hashed.append(word_hash)?

1 Answer

10

Two changes are required. See the commented lines:

import hashlib

not_hashed = []
hashed = []
while True:
    word_hash = raw_input("Hello this is a python string convertor.\nAny thing you say will be encoded using hashes\nWhat is your message: ")
    not_hashed.append(word_hash) #Needs to append to 'not_hashed' rather than 'hashed'
    hash_object = hashlib.md5(word_hash.encode())
    hashed.append(hash_object.hexdigest()) #The md5 is a binary object 'hexdigest' will give you a human readable object
    print("This is your message")
    print("Not hashed: ")
    print(not_hashed)
    print("Hashed")
    print(hashed)

posted this

Have an answer?

JD

Please login first before posting an answer.