I am trying to write code which validate if given string is hash in one from following types: md4, sha1, sha256. My functions right now looks like:
def hash_is_md5(_hash) -> bool: search = re.compile(r"([a-fA-F\d]{32})").search return not bool(search(_hash) ) def hash_is_sha1(_hash) -> bool: if len(_hash) != 40: return False try: hash_int = int(_hash, 16) except ValueError: return False return True def hash_is_sha256(_hash) -> bool: if (len(_hash.encode("utf-8")) / 8) == 32: return True else: return False
But they doesn't work proper. Any ideas what I coded wrong?