AS Level · Topic 6.2
A-Level Computer Science 9618 / Topic 6 / AS

Reasonable is not correct.

Most damage to data integrity is not an attack at all: it is a mistyped value or a bit flipped by interference. Validation rejects data that cannot be right; verification checks that data was copied or transmitted exactly. Learn every named check and be ready to carry out each one by hand.

The key idea

Validation is an automatic check, done by the computer, that data is reasonable and follows set rules: range, format, length, presence, existence and limit checks and check digits. Verification checks that data has been copied correctly: during data entry by a visual check or double entry, and during data transfer by a parity check (byte or block) or a checksum. Both protect data integrity, but neither can prove that data is actually true: a valid, correctly typed date of birth can still be the wrong person's.

two different checks on the way into the system Source Validation Verification Verification during data transfer document is it reasonable?range, format, length... is it a true copy?visual, double entry did it arrive unchanged?parity byte, parity block, checksum neither proves the data is true
Fig. 1: validation asks whether data is reasonable; verification asks whether it was copied or transferred exactly
Section 01

Validation checks.

In the lab, run each validation routine with normal, abnormal, extreme and boundary data and watch which values are rejected.

CheckWhat it doesExample
Range checkData lies between a lower and an upper limitAn exam mark from 0 to 100
Limit checkData is checked against one limit onlyQuantity ordered must be 1 or more
Format checkData follows a set pattern of charactersA student ID of two letters then four digits, e.g. AB1234
Length checkData has a set number of characters, or a number within limitsA password of at least 10 characters
Presence checkData has been entered: the field is not emptySurname must be filled in
Existence checkData matches a value that already exists, for example in a file or tableA product code must be in the product table
Check digitAn extra digit calculated from the other digits is recalculated and comparedISBNs and bar codes
DECLARE Mark : INTEGER
REPEAT
    OUTPUT "Enter the mark (0 to 100)"
    INPUT Mark
    IF Mark < 0 OR Mark > 100 THEN
        OUTPUT "Invalid: the mark must be from 0 to 100"
    ENDIF
UNTIL Mark >= 0 AND Mark <= 100
Worked example A format and length check
Write a function ValidID that returns TRUE only if its parameter is exactly six characters: two upper-case letters followed by four digits.
  1. Length check first: if LENGTH(ID) is not 6, the ID is invalid.
  2. Use MID to take one character at a time. Characters 1 and 2 must lie from "A" to "Z"; characters 3 to 6 must lie from "0" to "9".
  3. A flag starts TRUE and is set to FALSE by any failing character:
    FUNCTION ValidID(ID : STRING) RETURNS BOOLEAN
        DECLARE Valid : BOOLEAN
        DECLARE Index : INTEGER
        DECLARE Ch : STRING
        Valid ← TRUE
        IF LENGTH(ID) <> 6 THEN
            Valid ← FALSE
        ELSE
            FOR Index ← 1 TO 6
                Ch ← MID(ID, Index, 1)
                IF Index <= 2 THEN
                    IF Ch < "A" OR Ch > "Z" THEN
                        Valid ← FALSE
                    ENDIF
                ELSE
                    IF Ch < "0" OR Ch > "9" THEN
                        Valid ← FALSE
                    ENDIF
                ENDIF
            NEXT Index
        ENDIF
        RETURN Valid
    ENDFUNCTION
Answer: ValidID("AB1234") returns TRUE; ValidID("A12345") and ValidID("AB123") return FALSE.
Examiner trap

Validation cannot tell you the data is correct, only that it is reasonable. A mark of 67 typed instead of 76 passes a 0 to 100 range check.

Section 02

Check digits.

A check digit is calculated from the other digits of a code and added to the end. When the code is entered, the computer repeats the calculation. A common 9618 method is modulo 11 with weights; the lab shows the ISBN-13 method, which uses weights 1 and 3 and modulo 10.

Worked example Calculate a check digit
Calculate the modulo 11 check digit for the code 3152, using weights 5, 4, 3, 2.
  1. Products: 3 × 5 = 15, 1 × 4 = 4, 5 × 3 = 15, 2 × 2 = 4.
  2. Total: 15 + 4 + 15 + 4 = 38.
  3. 38 MOD 11 = 5 (since 3 × 11 = 33).
  4. Check digit = 11 − 5 = 6. Check: 38 + 6 × 1 = 44 and 44 MOD 11 = 0.
Answer: 6, so the full code is 31526
Worked example Catch a transposition
The code 31526 is typed as 13526. Show that the error is detected.
  1. Weights 5, 4, 3, 2, 1: 1 × 5 + 3 × 4 + 5 × 3 + 2 × 2 + 6 × 1.
  2. 5 + 12 + 15 + 4 + 6 = 42.
  3. 42 MOD 11 = 9, which is not 0.
Answer: The code is rejected, so the swapped digits are caught
Your turn
Calculate the modulo 11 check digit for 2468, using weights 5, 4, 3, 2.
Stage 1 · Learn

Check what the sim just showed you

Four quick checks. Each correct answer earns XP and records this skill on your profile.

Quick check+10 XP

Which check would reject a date of birth field left blank?

Quick check+10 XP

In the lab, with even parity, which received byte shows an error?

Quick check+10 XP

What is the main purpose of verification during data entry?

Quick check+10 XP

Using weights 5, 4, 3, 2 and modulo 11, what is the check digit for 1234?

Section 03

Verification: copied exactly?

In the lab, flip a bit in a parity block and see how the failing row and the failing column meet at the changed bit.

MethodWhenHow it works
Visual checkData entryThe user compares the data on screen with the source document and corrects any differences
Double entryData entryData is entered twice (often by two people); the computer compares the two and reports any mismatch
Parity byteData transferSender and receiver agree on even or odd parity; a parity bit makes the count of 1s in each byte even (or odd); the receiver recounts
Parity blockData transferA parity bit on each byte and a parity byte for each column of a block; a single wrong bit is found where the failing row and column cross, so it can be corrected
ChecksumData transferThe sender calculates a value from the block (e.g. the sum of the bytes, ignoring overflow) and sends it; the receiver recalculates and compares
Worked example Parity block
A block is sent with even parity. The first bit of each byte is the parity bit. The block received is: 01011001, 11100111, 00011010, 01111000, and the parity byte 11010100. Find the error.
  1. Count the 1s in each byte: 4, 6, 3, 4. Byte 3 has an odd number of 1s, so it is wrong.
  2. Count the 1s in each column (including the parity byte). Column 5 holds 1, 0, 1, 1, 0: three 1s, so it fails; every other column is even.
  3. The error is the bit in byte 3, column 5. It was received as 1, so it should be 0.
Answer: Byte 3 should be 00010010
Worked example Checksum
Four bytes with denary values 120, 75, 90 and 43 are sent. The checksum is the sum MOD 256. Calculate it.
  1. 120 + 75 + 90 + 43 = 328.
  2. 328 is too big for one byte, so take 328 MOD 256 = 72.
Answer: Checksum = 72
Examiner trap

A parity check misses an even number of changed bits in the same byte, because the count stays even. And neither validation nor verification can tell if the source document itself was wrong.

Stage 2 · Exam

Exam-style questions

Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.

Finish the four checks above to unlock the exam questions
Exam style+20 XP

A field must hold a code that is already stored in the customer table. Which validation check is this?

Exam style+20 XP

Which statement about a parity block is correct?

Exam style+20 XP

A 7-bit code 1100101 is sent with odd parity, the parity bit added on the left. What byte is sent?

Exam style+20 XP

An operator types a quantity of 15 instead of 51. Which check is most likely to detect this?

Skill unlocked

Validation and verification, checked.

This skill is now recorded on your profile. Keep the chain going.

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
Range, format, length, presence, existence and limit checks, check digits, visual checks and double entry, parity bytes, parity blocks and checksums.