Lets say i have a string like:
string = '456878921'
I would like to run this string through every hashing type python can offer from some package (lets say hashlib), so ideally, solution for this problem would be something like:
hashes = ['md5', 'sha256']
for n in hashes:
print(str(n) + ": " + str(hashlib.n(string).hexdigest())
Is this even possible in python?
You can use getattr
:
bytes = string.encode('utf-8') # hashlib algorithms require bytes!
for h in hashes:
hash = getattr(hashlib, h)
print(f'{h}: {hash(bytes).hexdigest()}')