← VCE Data Analytics U4O2

Hashing functions

A one-way function that turns any input into a fixed-length value. The same input always gives the same hash, a tiny change gives a very different one, and it cannot be reversed.

Understanding Hashing functions in VCE Data Analytics U4O2

What it does: Changing just one character produces a very different hash, so the two hash values are not equal. A one-letter input and a huge file both give a hash of the same length, so the lengths are equal. Hashing is one-way. Unlike encryption, there is no key that turns the hash back into the input. Encryption is designed to be decrypted by someone with the key. Hashing is not designed to be reversed. Hash functions are one-way, so there is no way to run them backwards. Hashing is deterministic: identical inputs always produce identical hashes, which is how hashes are used to check data.

Common mistakes: The program is checking that the same input gives the same hash. Changing 'cat' to 'Cat' changes the input, so the hashes would differ. Line 2 should hash "cat" again. A hash function always gives a fixed-length output, whatever the input size. The two hashes have equal lengths, so the test should be LEN(h1) = LEN(h2), not <.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 44–79) and word search (Modules 44–113).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A hash function is a one-way function. Which statement is correct?
A hash cannot be reversed to get the original inputA hash can be decrypted with the right key to get the original input
Matches
original = decrypt(hashValue)
↓
A hash function is one-way, so a hash cannot be reversed or decrypted to get the original input back.
Applying
Meanings
Term
hash function
Meaning
A one-way function that turns any input into a fixed-length value. The same input always gives the same hash, a tiny change gives a very different one, and it cannot be reversed.
Practice
import hashlib
Testing
Gaps
hashlib
Check Answer
Spots
1SET a ← HASH("cat")
2SET b ← HASH("Cat")

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Gila Monster' badge — Patient Coder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A hash function is a one-way function. Which statement is correct?
A. A hash cannot be reversed to get the original input ✓
B. A hash can be decrypted with the right key to get the original input
Hashing is one-way. Unlike encryption, there is no key that turns the hash back into the input.
2. A student hashes the word 'apple' and the hash is 32 characters long. What will the hash of a 5,000-word essay look like?
A. It will also be 32 characters long ✓
B. It will be much longer than 32 characters
A hash function always gives a fixed-length output, no matter how big or small the input is.
3. You hash the same file twice using the same hash function. What happens?
A. You get exactly the same hash both times ✓
B. You get a different hash each time
The same input always gives the same hash. This is why hashes can be used to check data.
4. A single letter in a document is changed and the document is hashed again. What is the result?
A. A hash that is almost the same as before
B. A completely different hash ✓
A tiny change to the input gives a very different hash. This makes tampering easy to spot.
5. Which describes the difference between hashing and encryption?
A. Hashing can be reversed with a key, while encryption is one-way
B. Hashing is one-way, while encryption can be reversed with a key ✓
Encryption is designed to be decrypted by someone with the key. Hashing is not designed to be reversed.

Match the Pairs

SHA-256("password") → Runs the input through a hash function to produce a fixed-length 64-character hash value
hash("data") == hash("data") → The same input always gives the same hash, so the comparison is true
A small change to the input gives a completely different hash → hash("Cat") != hash("Cap")
The output is a fixed length, however long the input is → len(hash("a")) == len(hash(bigFile))
original = decrypt(hashValue) → A hash function is one-way, so a hash cannot be reversed or decrypted to get the original input back.
hash("Hi") = 2 characters long → The hash length depends on the input, but it should be fixed whatever the input size.

Key Term

hash function
A one-way function that turns any input into a fixed-length value. The same input always gives the same hash, a tiny change gives a very different one, and it cannot be reversed.

Fill in the Blanks

1. import hashlib h = hashlib.sha256(b"hi").hexdigest() print(h)
Hint: Type the Python keyword that loads a module so you can use its hash functions.
2. h1 = hashlib.sha256(b"cat").hexdigest() h2 = hashlib.sha256(b"cat").hexdigest() print(h1 == h2)
Hint: Type the operator that checks two values are equal. The same input always gives the same hash, so this prints True.
3. h = hashlib.sha256(b"a").hexdigest() print(len(h))
Hint: Type the function that counts characters. A hash has a fixed length however long the input is.
4. h1 = hashlib.sha256(b"pass1").hexdigest() h2 = hashlib.sha256(b"pass2").hexdigest() print(h1 != h2)
Hint: Type the operator that checks two values are different. A tiny change in the input gives a very different hash.
5. stored = hashIt("Secret1") entered = "Secret1" print(hashIt(entered) == stored)
Hint: Type the name of the function already used on the first line. A hash cannot be reversed, so you hash the entered text and compare the results.

Spot the Error

Question 1
A SET a ← HASH("cat")
B SET b ← HASH("Cat")
C IF a = b THEN
D OUTPUT "Same hash"
Line B — The program is checking that the same input gives the same hash. Changing 'cat' to 'Cat' changes the input, so the hashes would differ. Line 2 should hash "cat" again.
Question 2
A SET h1 ← HASH("a")
B SET h2 ← HASH("a much longer text")
C IF LEN(h1) < LEN(h2) THEN
D OUTPUT "Fixed length"
Line C — A hash function always gives a fixed-length output, whatever the input size. The two hashes have equal lengths, so the test should be LEN(h1) = LEN(h2), not <.
Question 3
A SET original ← file
B SET received ← HASH(download)
C IF original = received THEN
D OUTPUT "File unchanged"
Line A — To check integrity we compare two hashes. Line 1 stores the raw file instead of its hash, so it would never equal the hash on line 2. It should be SET original ← HASH(file).
Question 4
A SET h1 ← HASH("score 90")
B SET h2 ← HASH("score 91")
C IF h1 = h2 THEN
D OUTPUT "Very different"
Line C — A tiny change to the input gives a very different hash. The hashes of "score 90" and "score 91" are not equal, so the test should be h1 ≠ h2.
Question 5
A import hashlib
B text = "hello".encode()
C h = hashlib.sha256[text]
D print(h.hexdigest())
Line C — sha256 is a hashing function, so it must be called with round brackets, sha256(text). Square brackets try to index it and cause an error.

Student with a class code? Join your class →