xxxxxxxxxx
import hashlib
hash_object = hashlib.sha256(b'Hello World')
hex_dig = hash_object.hexdigest()
print(hex_dig)
xxxxxxxxxx
import hashlib
def hash_string(string):
# Create a hash object using SHA-256 algorithm
hash_object = hashlib.sha256()
# Convert the string to bytes and update the hash object
hash_object.update(string.encode('utf-8'))
# Get the hashed string in hexadecimal form
hashed_string = hash_object.hexdigest()
return hashed_string
# Example usage
string_to_hash = "Hello World"
hashed_string = hash_string(string_to_hash)
print(hashed_string)