← VCE Data Analytics U4O2

Using hashes to check data integrity

Hash the file before and after transfer. If both hashes (checksums) match, the data is unchanged. A different hash shows the file was altered or tampered with, so its integrity is lost.

Understanding Using hashes to check data integrity in VCE Data Analytics U4O2

What it does: Running a hashing function over the file produces the checksum the receiver compares against. The comparison of the new hash with the original hash is how the receiver checks that the data is unchanged. Matching hashes show the data has not changed. A hash does not encrypt anything. A checksum is a hash of the file's data. It is used to detect changes, not to control access. A good hash function gives a very different output for even a small change, which makes tampering detectable. A mismatch means the integrity of the file is lost, so the data should not be relied on for decisions until a verified copy is obtained.

Common mistakes: The hash after transfer must be calculated from the received copy of the file, not from the earlier hash. It should be after ← HASH(copy). Both hashes must use the same algorithm. A different algorithm gives a different value even for an identical file. It should be got ← SHA256(download).

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 student downloads a file and its hash matches the hash published by the website. What does this show?
The file is unchanged, so its integrity is intactThe file has been encrypted during the download
Matches
Only hash the file after transfer, then assume it is unchanged
↓
With no hash from before the transfer there is nothing to compare against, so tampering cannot be detected. The file must be hashed before and after.
Applying
Meanings
Term
hash comparison
Meaning
Hash the file before and after transfer. If both hashes (checksums) match, the data is unchanged. A different hash shows the file was altered or tampered with, so its integrity is lost.
Practice
hashBefore ← HASH(file)
Testing
Gaps
hashBefore ← (file)
Check Answer
Spots
1before ← HASH(file)
2after ← HASH(before)

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

The 'Lion's Mane Jellyfish' badge — Set Operator, 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 student downloads a file and its hash matches the hash published by the website. What does this show?
A. The file is unchanged, so its integrity is intact ✓
B. The file has been encrypted during the download
Matching hashes show the data has not changed. A hash does not encrypt anything.
2. A file's hash before sending is different from its hash after it arrives. What is the most likely cause?
A. The file was altered or corrupted in transfer ✓
B. The file arrived exactly as it was sent
Even a tiny change to a file produces a completely different hash, so a mismatch signals the data has changed.
3. Which step is needed to check a file's integrity using a hash?
A. Hash the file before and after transfer, then compare the two ✓
B. Hash the file once and assume it is safe
Integrity is checked by comparing two hashes. One hash on its own tells you nothing about whether the file changed.
4. What is a file checksum?
A. A password that locks the file
B. A hash value calculated from a file's contents ✓
A checksum is a hash of the file's data. It is used to detect changes, not to control access.
5. An attacker changes one number in a spreadsheet during transfer. What happens to its hash?
A. It stays the same, so the tampering is hidden
B. It changes, so the tampering can be detected ✓
A good hash function gives a very different output for even a small change, which makes tampering detectable.

Match the Pairs

sha256(before) == sha256(after) → The two hashes match, so the file has not changed during transfer and its integrity is intact
sha256(before) != sha256(after) → The hashes differ, so the file was altered, corrupted or tampered with and its integrity is lost
A file checksum is the hash of a file, published by the sender so the receiver can check the download → checksum = sha256(file)
After a transfer, the receiver hashes the received file and compares it with the sender's hash to detect tampering → if sha256(received) == sentHash
Only hash the file after transfer, then assume it is unchanged → With no hash from before the transfer there is nothing to compare against, so tampering cannot be detected. The file must be hashed before and after.
Hashes differ, so the file is unchanged and safe to use → Different hashes mean the file has changed. It may have been tampered with or corrupted, so it should not be trusted.

Key Term

hash comparison
Hash the file before and after transfer. If both hashes (checksums) match, the data is unchanged. A different hash shows the file was altered or tampered with, so its integrity is lost.

Fill in the Blanks

1. hashBefore ← hash(file)
Hint: Type the function that turns the file into a fixed-length fingerprint (checksum).
2. IF hashBefore = hashAfter THEN OUTPUT "Data unchanged" ENDIF
Hint: Type the operator that checks whether the two hashes are equal.
3. IF hashBefore ≠ hashAfter THEN OUTPUT "File was tampered with" ENDIF
Hint: Type the operator that is true when the two hashes are different, showing the data changed.
4. received ← download(url) hashAfter ← hash(received)
Hint: Type the variable that holds the file that arrived after transfer, so it can be hashed again.
5. IF checksum = published THEN OUTPUT "Safe" ELSE OUTPUT "Altered" ENDIF
Hint: Type the keyword that runs when the checksums do not match.

Spot the Error

Question 1
A before ← HASH(file)
B after ← HASH(before)
C IF before = after THEN
D OUTPUT 'Unchanged'
E ELSE OUTPUT 'Tampered'
Line B — The hash after transfer must be calculated from the received copy of the file, not from the earlier hash. It should be after ← HASH(copy).
Question 2
A sent ← SHA256(report)
B got ← MD5(download)
C IF sent = got THEN
D OUTPUT 'Integrity kept'
Line B — Both hashes must use the same algorithm. A different algorithm gives a different value even for an identical file. It should be got ← SHA256(download).
Question 3
A expected ← 'a94f3c'
B actual ← CHECKSUM(expected)
C IF actual = expected THEN
D OUTPUT 'File is intact'
Line B — The checksum must be calculated from the downloaded file. Calculating it from the expected value tells us nothing about the file. It should be actual ← CHECKSUM(file).
Question 4
A h1 ← COUNT(contract)
B SEND contract TO client
C h2 ← HASH(received)
D IF h1 ≠ h2 THEN ALERT
Line A — A hash function is needed to create a fingerprint of the data. Counting does not detect small changes. It should be h1 ← HASH(contract).
Question 5
A before ← file
B UPLOAD file
C after ← HASH(file)
D IF before ≠ after THEN
E OUTPUT 'Altered'
Line A — The variable must store the hash of the file, not the file itself. Otherwise a hash is compared with a whole file and the check is meaningless. It should be before ← HASH(file).

Student with a class code? Join your class →