Complete the code to create an MD5 hash of a string in Python.
import hashlib hash_object = hashlib.md5() hash_object.update([1].encode()) print(hash_object.hexdigest())
The string password123 is encoded and passed to the MD5 hash function to generate the hash.
Complete the code to create a SHA-256 hash of a string in Python.
import hashlib hash_object = hashlib.[1]() hash_object.update('hello world'.encode()) print(hash_object.hexdigest())
The sha256 function from hashlib creates a SHA-256 hash object.
Fix the error in the code to correctly generate an MD5 hash.
import hashlib hash_object = hashlib.md5('data'.[1]()) print(hash_object.hexdigest())
The string must be encoded before passing to the MD5 function. Calling encode() converts the string to bytes.
Fill both blanks to create a SHA-1 hash of a string and print the hexadecimal digest.
import hashlib hash_object = hashlib.[1]() hash_object.[2]('example'.encode()) print(hash_object.hexdigest())
The sha1 function creates the hash object, and update feeds the encoded string to it.
Fill all three blanks to create a SHA-512 hash of a string and print the hexadecimal digest.
import hashlib hash_object = hashlib.[1]() hash_object.[2]('secure'.encode()) print(hash_object.[3]())
sha512 creates the hash object, update adds the encoded string, and hexdigest returns the hash as a readable hex string.