Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
A dictionary as a function selector solution in Clear category for Simple Hashlib by Splitter
import hashlib
def checkio(hashed_string, algorithm):
functions = {'md5': hashlib.md5, 'sha224': hashlib.sha224,
'sha256': hashlib.sha256, 'sha384': hashlib.sha384,
'sha512': hashlib.sha512, 'sha1': hashlib.sha1}
# It is necessary to encode input string before passing it into a function.
return functions[algorithm](hashed_string.encode()).hexdigest()
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio('welcome', 'md5') == '40be4e59b9a2a2b5dffb918c0e86b3d7'
assert checkio('happy spam', 'sha224') == '6e9dc3e01d57f1598c2b40ce59fc3527e698c77b15d0840ae96a8b5e'
March 16, 2020
Comments: