← ACARA Digital Technologies Years 9–10

One-way functions

A calculation that is easy to do forwards but practically impossible to reverse, like mixing paint. It is the idea behind hashing and public-key encryption.

Understanding One-way functions in ACARA Digital Technologies Years 9–10

What it does: The mix() call is the easy forward step. The paint analogy shows that going backwards from green to the original colours is practically impossible. This easy forward, hard backward gap is what RSA public-key encryption relies on. Hashing is one-way, so the stored hash does not reveal the password. The site hashes what you type and compares the two hashes. Caesar and rail fence ciphers are easily reversed with the key. Hashing and public-key encryption rely on one-way ideas. You cannot easily unmix purple into the exact original red and blue. This is the paint idea behind one-way functions.

Common mistakes: The one-way function here is multiplying two primes, which is easy forwards but very hard to reverse. Adding them would be easy to undo. Line 3 should be n = p * q. The hashing library is called hashlib, not hashlip. Without the correct import, the program cannot use the one-way hash function sha256. Line 1 should be import hashlib.

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 876–944) and word search (Modules 860–944).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A one-way function is easy to calculate forwards but practically impossible to reverse.
TrueFalse
Matches
hash = sha256("cat") original = reverse(hash) # gets back "cat"
↓
This assumes a one-way function can be reversed. A hash cannot be run backwards to recover the original input.
Applying
Meanings
Term
one-way function
Meaning
A calculation that is easy to do forwards but practically impossible to reverse, like mixing paint. It is the idea behind hashing and public-key encryption.
Practice
p = 10007
Testing
Gaps
print(p q)
Check Answer
Spots
2q = 53
3n = p + q

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

The 'Spider' badge — Web Weaver, 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 one-way function is easy to calculate forwards but practically impossible to reverse.
A. False
B. True ✓
That is the definition. Going forwards is quick, but working backwards from the result is not realistic.
2. Which is the best example of a one-way function?
A. Mixing two paint colours together ✓
B. Folding a piece of paper in half
Mixing paint is easy, but you cannot separate the mixed paint back into the original colours. Folding paper can easily be undone.
3. Which statement is true about multiplying and factoring large prime numbers?
A. Multiplying two primes is easy, but factoring the answer back into them is very hard ✓
B. Factoring the answer back into two primes is just as easy as multiplying them
This easy forward, hard backward gap is what RSA public-key encryption relies on.
4. Why is a one-way function useful for storing passwords as hashes?
A. A thief who steals the hash cannot easily work backwards to the password ✓
B. The hash can be reversed by the website to show the original password
Hashing is one-way, so the stored hash does not reveal the password. The site hashes what you type and compares the two hashes.
5. Which direction of a one-way function is the hard one?
A. Forward, from the input to the result
B. Backward, from the result to the original input ✓
Forward is easy. Backward is the part that is practically impossible.

Match the Pairs

7919 * 7907 → Multiplying two primes is quick and easy, even for a computer. This is the easy forward direction of a one-way function.
factor(62615533) → Working backwards from a big product to find the two primes is extremely hard. This is the hard backward direction of a one-way function.
Mixing blue and yellow paint to get green is easy, but you cannot easily unmix the green back into the two paints. → green = mix(blue, yellow)
A hash function turns any input into a fixed-length output, but you cannot work backwards from the output to the input. → digest = sha256(password)
hash = sha256("cat") original = reverse(hash) # gets back "cat" → This assumes a one-way function can be reversed. A hash cannot be run backwards to recover the original input.
# Factoring is easy, multiplying is hard n = p * q → The comment has the directions the wrong way round. Multiplying two primes is easy, and factoring the result is the hard direction.

Key Term

one-way function
A calculation that is easy to do forwards but practically impossible to reverse, like mixing paint. It is the idea behind hashing and public-key encryption.

Fill in the Blanks

1. p = 61 q = 53 print(p * q)
Hint: Type the operator that multiplies two primes together, the easy forward direction.
2. n = 3233 print(n % 61)
Hint: Type the operator that gives the remainder after division. A result of 0 shows the number is a factor.
3. import hashlib print(hashlib.sha256(b"paint").hexdigest())
Hint: Type the name of the hash function used to turn the data into a digest.
4. def mix(blue, yellow): return blue + yellow print(mix(5, 3))
Hint: Type the keyword that starts a function definition. Mixing is the easy forward step.
5. digest = hashlib.sha256(b"cat").hexdigest() print(len(digest))
Hint: Type the built-in function that counts how many characters are in the digest.

Spot the Error

Question 1
A p = 61
B q = 53
C n = p + q
D print(n)
Line C — The one-way function here is multiplying two primes, which is easy forwards but very hard to reverse. Adding them would be easy to undo. Line 3 should be n = p * q.
Question 2
A import hashlip
B data = b'cat'
C h = hashlib.sha256(data)
D print(h.hexdigest())
Line A — The hashing library is called hashlib, not hashlip. Without the correct import, the program cannot use the one-way hash function sha256. Line 1 should be import hashlib.
Question 3
A n = 3233
B for f in range(2, n):
C if n % f == 0:
D print(n)
E break
Line D — The loop is trying every number to factor n, which is the slow backward direction. When a factor f is found, the program should print f, not n. Line 4 should be print(f).
Question 4
A def one_way(x):
B retrun (x * x) % 10
C print(one_way(7))
Line B — The keyword is spelled return, not retrun. The typo is a syntax error, so the function can never give back its forwards result. Line 2 should be return (x * x) % 10.
Question 5
A import hashlib
B pw = 'cat123'
C h = hashlib.sha256(pw)
D print(h.hexdigest())
Line B — hashlib works on bytes, not on a normal string. The b prefix turns the password into bytes so the one-way hash can be calculated. Line 2 should be pw = b'cat123'.

Student with a class code? Join your class →