Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1import hashlib | ATurns a string into bytes, which is the form the hash function needs as input | |
| 2text.encode() | Bprint(hashlib.sha256('cat'.encode()).hexdigest()) | |
| 3The same input always gives the same hash, so two hashes can be compared to check that text matches | Chashlib.sha256(a.encode()).hexdigest() == hashlib.sha256(b.encode()).hexdigest() | |
| 4Turn the finished SHA-256 hash into a fixed-length hexadecimal string you can print | Dhexdigest() is missing, so this gives a hash object, not the readable hex text. Add .hexdigest() at the end. | |
| 5hashlib.sha256('cat').hexdigest() | ELoads Python's built-in hashing module so you can use hash functions like SHA-256 | |
| 6hashlib.sha256('cat'.encode()) | FThe text was not turned into bytes with encode(), so Python raises a TypeError. It should be 'cat'.encode(). |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
hashlib.sha256(text.encode()).hexdigest() — Python code that turns text into bytes, hashes it with SHA-256 and returns a fixed-length hex string. Same input gives the same hash; one changed letter gives a new hash.import hashlibd = hashlib.sha256(s.encode()).hexdigest()d = hashlib.sha256(s.encode()).hexdigest()d = hashlib.sha256(s.encode()).hexdigest()h1 = hashlib.sha256(s.encode()).hexdigest()
h2 = hashlib.sha256(t.encode()).hexdigest()
print(h1 == h2)