A checksum is a number calculated from a block of data and sent with it. The receiver repeats the calculation. If the numbers differ, the block changed on the way, so the receiver rejects it.
Questions ask you to calculate a checksum, compare two values and say what the method can and cannot do. The words you choose matter as much as the sum.
This lesson comes after parity in data transmission and checking.
How does a simple checksum work?
To keep the arithmetic easy, this lesson uses a teaching version: add the values, then take the remainder after dividing by 100. Real checksums use different rules, so follow your syllabus and teacher for the version you must know.
- Add all the data values.
- Take the sum MOD 100 to get the checksum.
- Send the data and the checksum together.
- The receiver repeats steps 1 and 2 on the data that arrived and compares.
Worked example
Four data values are sent: 52, 87, 19, 66.
total ← 0
FOR i ← 1 TO 4
total ← total + Data[i]
NEXT i
checksum ← total MOD 100
Trace:
| i | Data[i] | total |
|---|---|---|
| start | 0 | |
| 1 | 52 | 52 |
| 2 | 87 | 139 |
| 3 | 19 | 158 |
| 4 | 66 | 224 |
Then 224 MOD 100 = 24. Check by hand: 52 + 87 = 139, 139 + 19 = 158, 158 + 66 = 224, and 224 − 200 = 24.
Receiver, case 1. The block arrives as 52, 87, 91, 66. The total is 296, and 296 MOD 100 = 96. This does not equal 24, so the receiver detects an error.
Receiver, case 2. The block arrives as 87, 52, 19, 66. The total is still 224, so the checksum is 24. The check passes even though two values swapped places.
What mistake do students make?
A common line is: “The checksum makes the data secure, so nobody can change it.”
This is wrong. A checksum is a way to detect accidental changes. Someone who deliberately alters the data can work out the new checksum and send it along, so the receiver would see a match. The honest wording is: “A checksum can detect many accidental errors, but it does not stop a person from changing the data on purpose, and it can miss some changes such as swapped values.”
Check yourself
1. Calculate the checksum (sum MOD 100) for 14, 35, 28, 9.
Show answer
14 + 35 = 49, 49 + 28 = 77, 77 + 9 = 86. 86 MOD 100 = 86.
2. The sender’s checksum was 95 for the values 40, 25, 30. The receiver gets 40, 25, 31. Does the check pass?
Show answer
40 + 25 + 31 = 96, so the receiver’s checksum is 96. It differs from 95, so an error is detected.
3. Give one reason a checksum is not a security feature.
Show answer
Anyone changing the data can recalculate the checksum and replace it, so the receiver would see a match. It only detects accidental changes.
Where this leads next
Finally, separate checks that only notice problems from methods that repair them in error detection versus correction. Use the safe Python reasoning sandbox to write the sum-and-remainder loop yourself and test it with the values above. Then try the practice set.
If you can do the sum but your evaluation answers sound vague, a teacher can tighten the wording with you in online one-to-one Computer Science tuition.