Checksum

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Checksum

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Where does a checksum value come from?
A It is calculated from the data itself using a set rule
B It is chosen at random by the sender
2. How is a checksum sent to the receiver?
A Along with the data it was calculated from
B On a separate, slower connection after the data is deleted
3. What does the receiver do with the checksum it receives?
A Adds it to the data and stores it as part of the file
B Recalculates it from the received data and compares the two values
4. The sender and receiver must use which calculation?
A A different calculation each, to double-check the data
B The same calculation
5. The receiver's calculated checksum is different from the one that was sent. What does this mean?
A An error occurred during transmission
B The data arrived correctly

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1checksum = sum(data) % 256 AThe checksum is not calculated from the data. It must come from the data using a set rule, so a made-up value cannot show whether the data changed.
2if received_checksum == calculated_checksum: BThe sender calculates a value from the data itself using a set rule
3The checksum is sent with the data so the receiver can use it to check for errors CThe receiver must calculate the checksum again from the received data and compare it. Receiving a checksum does not prove the data is correct.
4The sender and receiver must use the same calculation, so the receiver repeats the sender's rule Dsend(data, checksum)
5checksum = 42 # a fixed number chosen at random Enew_checksum = sum(received_data) % 256
6Receiver: the checksum arrived, so the data must be correct FThe receiver compares the sent checksum with the one it calculated again

Definitions

checksum

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
checksum ← ___(data) MOD 256
2.
SEND data, ________
3.
calc ← SUM(received) ___ 256
4.
IF calc = checksum ____ OUTPUT "No error found"
5.
IF calc __ checksum THEN OUTPUT "Error detected"

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A data ← [12, 7, 30, 5]
B checksum ← SUM(data)
C SEND data
Question 2
A RECEIVE data
B newSum ← SUM(data)
C IF newSum = sentSum THEN
D OUTPUT "No error"
Question 3
A data ← [8, 15, 3, 22]
B sum ← 0
C FOR i ← 0 TO 3
D sum ← data[i]
E NEXT i
F SEND data, sum
Question 4
A RECEIVE data, sentSum
B newSum ← SUM(data)
C IF newSum = sentSum THEN
D OUTPUT "Error detected"
E ENDIF
Question 5
A data ← [6, 11, 9]
B checksum ← 100
C SEND data, checksum

Answer Key

Checksum
Section A: Quick Questions
Q1
A — It is calculated from the data itself using a set rule
Q2
A — Along with the data it was calculated from
Q3
B — Recalculates it from the received data and compares the two values
Q4
B — The same calculation
Q5
A — An error occurred during transmission
Section B: Match the Pairs
Q1
checksum = sum(data) % 256 → The sender calculates a value from the data itself using a set rule
Q2
if received_checksum == calculated_checksum: → The receiver compares the sent checksum with the one it calculated again
Q3
The checksum is sent with the data so the receiver can use it to check for errors → send(data, checksum)
Q4
The sender and receiver must use the same calculation, so the receiver repeats the sender's rule → new_checksum = sum(received_data) % 256
Q5
checksum = 42 # a fixed number chosen at random → The checksum is not calculated from the data. It must come from the data using a set rule, so a made-up value cannot show whether the data changed.
Q6
Receiver: the checksum arrived, so the data must be correct → The receiver must calculate the checksum again from the received data and compare it. Receiving a checksum does not prove the data is correct.
Section C: Definitions
Q1
checksum — A value calculated from a block of data by a set rule and sent with it. The receiver repeats the calculation and compares the results. If they differ, an error occurred.
Section D: Fill in the Blanks
Q1
checksum ← SUM(data) MOD 256
Q2
SEND data, checksum
Q3
calc ← SUM(received) MOD 256
Q4
IF calc = checksum THEN OUTPUT "No error found"
Q5
IF calc <> checksum THEN OUTPUT "Error detected"
Section E: Spot the Error
Q1
C — The checksum must be sent with the data so the receiver can compare it. The line should be SEND data, checksum.
Q2
A — The receiver needs the checksum that was sent with the data, otherwise sentSum has no value to compare against. It should be RECEIVE data, sentSum.
Q3
D — This overwrites sum on each pass, so only the last value is kept. The checksum must add every value: sum ← sum + data[i].
Q4
C — An error is detected when the two checksums are different, not equal. The test should be IF newSum <> sentSum THEN.
Q5
B — A checksum must be calculated from the data itself. A fixed number would not change if the data changed. It should be checksum ← SUM(data).