Data integrity
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Keeping data correct
- Integrity means data stays accurate. Two techniques protect it: validation and verification.
- They sound similar but do different jobs — a classic exam distinction.
Validation vs verification
- Validation checks data is reasonable as it is entered. Examples:
- Range check (age 0–120), length check (a phone number), format check (an email has an
@), presence check (not left blank).
- Range check (age 0–120), length check (a phone number), format check (an email has an
- Verification checks data was copied correctly. Examples:
- Double entry (type a password twice), or a visual check (read it back).
Checking data in transit
- When data travels, bits can flip. A checksum or check digit catches that.
- The sender calculates a small number from the data; the receiver recalculates it. If they differ, the data was corrupted.
number = "1389"
print(sum(int(d) for d in number) % 10) # a one-digit checksum
Your turn
- Compute a simple check digit by summing the digits modulo 10. Real systems (like barcodes and ISBNs) use cleverer versions of this idea.
Covers: A-Level 6.2 (validation/verification), IGCSE 2.2 (error detection).
Common mistakes
- A checksum or check digit spots accidental changes to data.
- Validation checks data is sensible; verification checks it was entered correctly.
Explore
Hashes detect tampering
Re-hash the data and compare: any change flips the digest.
A simple checksum helps catch typing errors. Add up the digits of number and take the result modulo 10. Print that single check digit.
Click Run to see the output here.
Now be the receiver. The sender transmitted the digits with check digit 8, but one digit got corrupted on the way. Recompute the checksum of received and print ERROR if it does not equal sent_check, else OK.
Click Run to see the output here.