12.3.3Advanced Networks and SecurityCore

Parity Blocks and Checksum Limits

Calculate the check information using an explicit algorithm, then construct an error the check misses. Detection capability depends on the error pattern, not only on whether a check value exists.

35 min Video by Craig'n'Dave Security and Error Detection
86. AQA A Level (7516-7517) SLR12 - 4.5.5 Error checking and correctionCurated by Kepler, not produced by us. Watch it before the notes below.
Open on YouTube

Before you start

  • Count ones under a declared even/odd parity rule.
  • Distinguish detecting one assumed error from proving arbitrary data are unchanged.

Watch, pause, try

Video by Craig'n'Dave. Use the shared AQA explanation for single parity and checksum foundations. Pearson also requires two-dimensional blocks, developed explicitly in the written lesson. Its negative-sum byte checksum is a supplied teaching rule, not every protocol’s algorithm; parity/checksum success cannot authenticate an active sender.

Viewing focus: Calculate even/odd and two-dimensional parity

After watching, attempt these questions before opening the answers. You can also use the written lesson below.

After watching 1: Add an even parity bit to each row and a final column-check row for data [[1,0,1],[1,1,0]], including the consistent corner. What syndrome follows flipping only data row zero, column one? Could flipping the four data corners at rows zero/one and columns zero/two evade every row/column check?

Show answer and reasoning

The encoded block is [[1,0,1,0],[1,1,0,0],[0,1,1,0]]. One flip at (0,1) makes row zero and column one fail, locating the intersection under the single-error assumption. Four rectangle-corner flips can preserve all checks because every affected row and column has two flips. The single-error inference does not justify arbitrary multi-error correction.

After watching 2: For the stated check byte c=−sum(data) mod 256, use bytes [31,250,17]. Calculate c and test changed data [32,249,17] against the same c. What can a passing unkeyed check establish about a deliberate sender alteration?

Show answer and reasoning

The sum is 298, so c=214 and data plus c total 512, divisible by 256. The changed data have the same sum and also pass. This check can detect some accidental corruption under its error model but cannot establish origin or resist an adversary who can preserve or recompute it. Use an appropriate authenticated mechanism when that is the requirement.

What you'll be able to do

  • Calculate even/odd and two-dimensional parity
  • Localise a single changed bit under a parity-block model
  • Calculate an eight-bit checksum and explain collisions
1

Count the bits under the specified parity rule

An even-parity bit makes the total number of ones in the protected group even; odd parity makes it odd. For data 1101, three ones require parity 1 for even parity and 0 for odd parity. The bit is a check on the group, not encryption. One flipped bit changes parity, while an even number of flips in the same group can preserve it.

Two-dimensional parity adds checks for rows and columns of a data block. Under the even-parity model below, each data row gets one parity bit and a final row checks the columns, including a consistent corner bit. For a single changed bit, one row and one column report failure, locating the intersection. This reasoning assumes the declared single-error model.

2

Test what a parity block can miss

Changing all four corners of a rectangle can flip two bits in each affected row and two in each affected column. Every even-parity check can still pass. Two-dimensional parity therefore does not prove that an arbitrary block is unchanged and must not be presented as detecting every possible corruption. Several failures can also make correction ambiguous.

The original code validates a rectangular binary block and computes parity by sums modulo two. It returns the failing row/column indices after a selected bit flip. The block includes parity positions; a single error in a parity position also has a detectable syndrome. Correcting data automatically needs a specified error assumption rather than guessing whenever any row happens to fail.

Python 3
def validate_bits(block):
    if not block or not block[0] or any(len(row) != len(block[0]) for row in block):
        raise ValueError('Use a nonempty rectangular block')
    if any(type(bit) is not int or bit not in (0, 1) for row in block for bit in row):
        raise ValueError('Use binary integer bits')

def add_even_parity(data):
    validate_bits(data)
    block = [list(row) + [sum(row) % 2] for row in data]
    bottom = [sum(row[column] for row in data) % 2 for column in range(len(data[0]))]
    bottom.append(sum(bottom) % 2)
    return block + [bottom]

def parity_errors(block):
    validate_bits(block)
    rows = [index for index, row in enumerate(block) if sum(row) % 2]
    columns = [column for column in range(len(block[0])) if sum(row[column] for row in block) % 2]
    return rows, columns

data = [[1, 0, 1, 1], [0, 1, 0, 1], [1, 1, 0, 0]]
block = add_even_parity(data)
print(block)
block[1][2] ^= 1
print(parity_errors(block))
Scroll horizontally to see the full code or table.
Even row/column parity with a final corner bit and a single-bit error at row 1, column 2.
3

State the checksum algorithm and its limits

This teaching checksum sums data bytes and stores the negative sum modulo 256, so data plus check byte have remainder zero. For bytes 12,250,9, the total is 271 and the check byte is 241, because 271+241=512. A different checksum algorithm, such as an Internet ones’-complement checksum, needs its own rules; do not mix their calculations.

Changing the data to 13,250,8 preserves the total and passes this simple checksum despite changing two values. A checksum is useful for its stated accidental-error model, but not an authentication proof against an active adversary who can recompute it. If authenticity is required, the system needs an appropriate cryptographic authentication mechanism and key/trust design, not just more confidence in an unkeyed arithmetic check.

Python 3
def check_byte(data):
    return (-sum(data)) % 256

data = bytes([12, 250, 9])
check = check_byte(data)
print(check)
print((sum(data) + check) % 256 == 0)
changed = bytes([13, 250, 8])
print((sum(changed) + check) % 256 == 0)
Scroll horizontally to see the full code or table.
An explicitly defined eight-bit modular-sum checksum with an independent undetected-change example.
4

Work through the problem

Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.

Example 1Supply even and odd parity bits for data 1101.
1The data contain three ones.
2Adding 1 makes four ones; adding 0 leaves three.
Answer
Even parity bit 1; odd parity bit 0.
Example 2Only parity row 1 and column 2 fail after one changed bit in the stated model. What can be inferred?
1One error affects exactly its row and column checks.
2Their intersection identifies row 1, column 2.
3The inference relies on the one-error assumption.
Answer
The single changed bit is at that intersection; arbitrary multi-error correction is not established.
Example 3Calculate the check byte for 12,250,9 using this lesson’s modular rule.
1Sum is 271.
2Choose a byte c with (271+c) mod 256=0.
3c=241 makes the sum 512.
Answer
241; a preserved sum can still conceal changed data.

Common mistakes to avoid

Claiming parity detects every possible error.
State which error patterns change the checks and give counterexamples.
Using the wrong checksum convention from another algorithm.
Write the supplied width, sum and complement/modulus rules first.

Key takeaways

  • Parity depends on the count rule and error pattern.
  • Two-dimensional checks can localise one error under that assumption.
  • Checksum success is neither universal integrity proof nor sender authentication.

Explore further

Return to this tomorrow

Close the notes and answer from memory. Revisit any explanation you cannot yet reconstruct.

  • Four rectangle-corner flips in an even row/column block can:
  • A valid simple checksum proves the message came from a trusted sender:

Test yourself

Answer a few questions, then review anything you missed.

Next step

Keep practising

Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.

Browse practice topics

Related lessons

All 3 lessons