Skip to content

Instantly share code, notes, and snippets.

@mecampbellsoup
Last active January 31, 2021 07:42
Show Gist options
  • Save mecampbellsoup/4ca99e74aad24266f7e66be52c989f92 to your computer and use it in GitHub Desktop.
Save mecampbellsoup/4ca99e74aad24266f7e66be52c989f92 to your computer and use it in GitHub Desktop.
# Write a Python program that prints the SHA256 hash of "Hello World" in hexadecimal.
import hashlib
import codecs
def sha256(s):
encoded = s.encode()
hash_object = hashlib.sha256(encoded)
print(hash_object.digest())
return(hash_object.digest())
encoded_digest = sha256("Hello World")
print("Hexadecimal of SHA256 hashed message:", codecs.encode(encoded_digest, 'hex'))
# ```
# 21:14:28 › python3 hello_world.py
# b'\xa5\x91\xa6\xd4\x0b\xf4 @J\x01\x173\xcf\xb7\xb1\x90\xd6,e\xbf\x0b\xcd\xa3+W\xb2w\xd9\xad\x9f\x14n'
# Hexadecimal of SHA256 hashed message: b'a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e'
# ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment