Security, privacy and integrity of data
One employee’s record on a company server can go wrong in three ways: it can be lost, read by the wrong person, or simply be wrong. A record can be kept safe and private and still hold a mistake, so each concern needs its own measures.
Follow each row from the record: the concern, what can go wrong, and the measure that protects it.
Definitions
The three terms sound alike, so the bold words carry the difference: use them when you define each one.
| Term | Meaning: the wording to use | Typical measures |
|---|---|---|
| Security of data | keeping data safe from loss or corruption, so it is there when needed and can be recovered | backups, firewall, anti-malware, passwords, access rights |
| Privacy of data | only authorised people can read the data or be given it | access rights, encryption |
| Integrity of data | making sure data is accurate, consistent and up to date | validation and verification |
Protect the data and the system
Protect the data
- An intruder can read, copy, change or delete it.
- It can be lost by accident: a disk failure, a file deleted in error, fire or flood.
- A business cannot work without it, so it must be recoverable.
Protect the system
- An intruder can plant malware or stop the system working.
- Staff need it running for their daily jobs.
- Logging in is for authorised users alone.
1 A hospital’s only copy of its patient records is on one disk, which fails. Which concern is this: security, privacy or integrity?
2 A patient’s date of birth is stored as 31/02/1990. Which concern is this, and which measure would catch it?
3 Give one measure for privacy and say how it protects the data.
- 1security: the data is lost; a backup kept elsewhere lets it be recovered
- 2integrity: the data is not accurate; validation (a check that the date exists) would reject it
- 3access rights: only authorised users can read the records (or encryption: a copy cannot be understood without the key)
Threats: viruses, spyware and hackers
Once a computer is connected to the internet, anything out there can try to reach it. Viruses and spyware are malware (malicious software); hackers are people who break in. All three come in through the network and internet connection.
Follow each threat from 1 to 3: how it gets in, what it does, and the harm (amber).
Describe the threat, then a matching method
For each threat, be able to say what it does and give a method that stops that threat.
| Threat | What it is | A method that restricts it, and how it works |
|---|---|---|
| Virus | malware that replicates (copies itself into other files) and can delete or corrupt data or fill storage | Anti-virus. How: checks each file and download, matches it against signatures of known viruses, quarantines or deletes a match |
| Spyware | malware that hides on the computer, secretly records keystrokes and passes them to a third party | Anti-spyware finds and removes it. Also: a firewall stops the log going out; a virtual keyboard leaves no keystrokes to record |
| Hacker | a person who gets into a system without permission: unauthorised access | Firewall. How: tests traffic in and out against rules and blocks what breaks them. Also: strong passwords; multi-factor or biometric authentication |
Virus or spyware?
Both are hidden malware, so three questions tell them apart: does it copy itself, what does it do to data, and does it send anything out?
| Virus | Spyware | |
|---|---|---|
| Copies itself? | yes: it replicates into other files | no |
| What it does to data | damages it: deletes or corrupts files | records it: keystrokes, passwords, card numbers |
| Sends data out? | no | yes, to a third party |
1 A program copies itself into every document on a shared drive. Which threat is it?
2 Name a method that stops spyware sending its log, and say how.
3 Give two different methods that restrict hacking.
- 1a virus: it replicates into other files
- 2a firewall: it checks outgoing traffic against rules and blocks the log leaving (or anti-spyware finds and removes it)
- 3any two: a firewall that blocks traffic breaking its rules; strong passwords; multi-factor or biometric authentication
Threats: phishing and pharming
A fake bank website can look exactly like the real one. Phishing and pharming both trick a user into typing confidential details into a fake website. They differ in how the user gets there.
Follow both routes: a message the user acts on (blue), or code that redirects a correct address (violet). Both end at the same fake site.
Compare the two
The two are easy to mix up because they end at the same fake site. Be able to give one similarity and one difference: the difference is always the route.
| Phishing | Pharming | |
|---|---|---|
| How it starts | a message posing as a trusted organisation | malicious code installed on the user’s PC |
| To the fake site | the user clicks a link in the message: user action is needed | the code redirects the request automatically, even when the genuine address is typed |
| Aim | to collect personal or financial data | the same |
| Restrict the risk | a spam filter; ignore unknown senders | anti-malware removes the code; also a VPN |
Identify the route to Leafline’s fake site
Leafline is an online plant shop. Some customers lose reward points after clicking a message link; others typed its correct address.
| Observed route | Threat and reason |
|---|---|
| Clicked a message posing as Leafline | Phishing: the user acted on the deceptive message. |
| Typed the correct address but was redirected | Pharming: installed code redirected the request. |
Both routes reach a fake copy that collects login details. A fake website is their similarity; the route to it is their difference.
1 A text message says a parcel is held and links to a payment page. Phishing or pharming? Why?
2 A user types the correct address of their bank and still reaches a fake site. Which threat is this, and what caused it?
3 Give one way to restrict each threat.
- 1phishing: it is a message, and the user must act on it by following the link
- 2pharming: malicious code installed on the computer redirected the request
- 3phishing: a spam filter, or do not follow links in unexpected messages; pharming: anti-malware that removes the redirecting code
User accounts, passwords and authentication
A computer cannot see who is at the keyboard. A user account gives each person a username, a password and their access rights. Authentication checks that the person logging in really owns the account.
Two checks in order: something the user knows, then a second factor. Fail either and access is denied.
Three kinds of authentication factor
Something you know
A password or PIN. No extra hardware, but it can be guessed, seen or forgotten.
Something you have
A phone with an authenticator app, a security token or a key card: an attacker must steal it too.
Something you are
Biometrics: fingerprint, face, iris or voice. Unique to the person and very hard to copy.
Why long, varied passwords?
A program can try every possible password in turn: possible passwords = (characters allowed)length. Times assume 10 billion guesses a second.
| Characters allowed | How many | Length | Possible | Time to try all |
|---|---|---|---|---|
| a–z only | 26 | 8 | 2.09 × 1011 | 21 seconds |
| a–z, A–Z, 0–9 | 62 | 8 | 2.18 × 1014 | 6.1 hours |
| all keyboard characters | 94 | 8 | 6.10 × 1015 | 7.1 days |
| all keyboard characters | 94 | 12 | 4.76 × 1023 | 1.5 million years |
A strong password
- At least a set number of characters.
- A mixture of upper and lower case, digits and symbols.
- Nothing connected to the user, such as a date of birth.
- Not reused for other accounts.
1 A bank asks for a password and then a fingerprint. Which two kinds of factor are these?
2 A PIN uses the digits 0 to 9 and has 4 digits. How many PINs are possible?
3 Why is a password and a security question not multi-factor authentication?
- 1something the user knows (password) and something the user is (biometric)
- 2104 = 10 000
- 3both are something the user knows: multi-factor needs two different kinds
Firewalls, anti-virus and anti-spyware
Not every packet from the internet should get in, and not every packet should leave. A firewall, in hardware or software, sits between a computer or network and the outside world and checks every packet going in or out. Anti-virus and anti-spyware find malicious software in files and downloads, and remove it or stop it arriving.
Applying the rules to five packets
Check each packet against the rules in order: the first rule that matches decides. Be able to do this for a new packet.
Rules, checked in order · deny list: 203.0.113.66
Packet 4 shows why outgoing traffic is checked too: spyware trying to send its log to a blocked address is stopped.
Scanning for malware
Anti-virus and anti-spyware
Do not confuse
A firewall does not scan the files already on a disk for viruses, and anti-virus software does not block a hacker’s connection. Anti-spyware is the tool aimed at spyware; anti-malware covers every kind.
1 Use the four rules. An incoming packet from 198.51.100.4 is sent to the web server on port 80. Which rule decides, and is it allowed?
2 An outgoing packet from PC 9 to 198.51.100.20 on port 443?
3 An incoming packet from 203.0.113.66 to PC 3 on port 443?
4 Why must anti-virus signatures be updated regularly?
- 1rule 4: blocked: port 80 matches neither allow rule
- 2rule 3: allowed
- 3rule 1: blocked: the address is on the deny list, and rule 1 is checked first
- 4new malware has signatures the old list does not contain, so it would not be recognised
Encryption, access rights and backups
A password can be beaten and a disk can fail, so some measures protect the data itself: encryption makes it unreadable, access rights limit who can use it, and backups let it be recovered.
Encryption: intercepted data cannot be understood
Follow the message across the network: anyone who intercepts it sees only the ciphertext. The receiver needs the key to turn it back into plaintext.
Stored data
An encrypted disk, file or database cannot be read by anyone who copies or steals it without the key.
Transmitted data
Data sent over a network is encrypted, e.g. HTTPS or a VPN, so intercepted data is meaningless.
Access rights: what each user may do
Read down one column to see everything a single user may do, or across a row to see who can change that file.
| File | Student | Teacher | Exams officer |
|---|---|---|---|
| Timetable | read-only | read-only | read/write |
| Class marks | no access | read/write | read-only |
| Exam papers before the exam | no access | no access | read/write |
Each account or group gets no access, read-only, or read and write for each file or table. Logging in does not give access to everything. In a database, a view can show a user only some of the data.
Backups and physical security
Backups
Regular copies kept in a separate place mean data can be recovered after a disk failure, a mistaken deletion, malware or fire. A backup does not prevent the loss.
Physical security
Lock the room that holds the server, and log off or lock a computer before leaving it, so no one can simply sit down and use it.
1 Use the toy shift of 3 to encrypt the word LOCK.
2 Using the table, what may a teacher do with the timetable, and with the exam papers?
3 A file server is encrypted and backed up every night. A fire destroys the server room. Which measure lets the school carry on, and why?
- 1ORFN: each letter moves 3 places on
- 2timetable: read-only; exam papers: no access
- 3the backup, if it is kept in a separate place: the data can be restored. Encryption does not prevent the loss
Digital signatures
A program you download says it comes from its maker, but it could have come from anyone, or been changed on the way. A digital signature lets the receiver check that a document really came from the claimed sender (authentic) and that it was not changed on the way.
Follow the sender’s two steps (hash, then encrypt the digest), then the receiver’s three (decrypt, hash again, compare). Name the key used at each step.
Hashing: a small change gives a completely different digest
Only one digit of the amount differs between the two documents. Compare their digests.
| Document | SHA-256 digest (first 24 of 64 hex digits) |
|---|---|
| Pay 250 to J. Okafor | de2ed590ca5782d6492d2e5b… |
| Pay 850 to J. Okafor | 7049b97bfd90f09ef05dd8e5… |
| Document and its SHA-256 digest |
|---|
| Pay 250 to J. Okafor de2ed590ca5782d6492d2e5b… |
| Pay 850 to J. Okafor 7049b97bfd90f09ef05dd8e5… |
The two digests agree in only 1 of the 24 digits shown, by chance. An altered document gives a different digest 2, so the comparison at step 6 fails.
What it proves
- Authentic: the private key is held by the sender alone, so a signature that decrypts with their public key to the right digest must have come from them.
- Unchanged: any change to the document gives a different digest 2.
Do not confuse
- The digest is encrypted, not the whole document.
- Private key signs; the matching public key checks.
- A signature does not hide the document: encrypt it as well if it is confidential.
1 Which key does the sender use to make the signature? Which key does the receiver use to check it?
2 On the way, “Pay 250” is changed to “Pay 850”. What does the receiver find when it compares the digests?
3 Does a digital signature keep the document secret? Explain.
- 1the sender’s private key signs (encrypts the digest); the sender’s public key checks (decrypts it)
- 2digest 2, from the changed document, differs from digest 1, so the document is rejected
- 3no: the document travels readable. It must also be encrypted to keep it secret
Security measures for stand-alone computers and networks
Link thirty computers into a network and there are more ways in and more users. So a network needs a firewall at the router, and accounts, rights and backups set on the server.
Start with the measures one computer needs. Then follow traffic in from the internet: it must pass the firewall before it reaches the server or a client PC.
Measures for stored data and for data in transit
First ask where the data is: sitting on a disk, or travelling across a network. Each needs its own protection.
| Data | Measures | How each protects it |
|---|---|---|
| Stored on a PC or server | physical security; access rights; an encrypted disk; backups | no one can sit down and copy it; only allowed users can open it; a stolen copy is unreadable; a lost copy can be restored |
| Sent over a network | encryption (e.g. over a VPN); a firewall | an intercepted copy cannot be understood without the key (a firewall blocks traffic but does not hide content) |
Reducing the malware risk
Each row gives a measure and why it lowers the risk: give both.
| Where | Measure | Why the risk falls |
|---|---|---|
| Network connection | a firewall compares data in and out with set rules and blocks what is not allowed | fewer ways in |
| Downloads | software only from trusted, official sites | fewer files carry hidden malware |
| USB drives | a portable-storage policy: block or scan drives | infected files are not copied in |
| User accounts | strong passwords; multi-factor authentication (app code or biometrics); no admin rights | a stolen password alone is not enough; malware cannot install itself |
| Files on the PC | anti-malware, signatures updated daily | known malware is found and quarantined |
1 A school links 30 PCs to the internet. Where should the firewall go, and why there?
2 Give two different measures that protect data sent over the network.
3 Why does a user with no admin rights lower the malware risk?
- 1at the router, between the school network and the internet: every packet in or out passes it
- 2encryption (for example over a VPN), so an intercepted copy cannot be understood; a firewall, which blocks traffic that breaks its rules
- 3malware run by that user cannot install itself or change system settings
Validation and verification
A stored value is only useful if it is right. Errors get into data at two points: when it is entered and when it is transferred. Validation and verification both guard against them, but they ask different questions.
One check asks “is it reasonable?”, the other “is it the same as the original?”. Follow one quantity, 4075, as it is typed wrongly: the first lets it through, the second catches it.
Validation compared with verification
Neither check catches every mistake, which is why a system often uses both. Be able to say which one a method is, and what each can still let through.
| Validation | Verification | |
|---|---|---|
| Tests… | the data against set rules (bounds, format, type): is it reasonable? | the data against the original, or that it did not change in transfer: is it the same? |
| Carried out by | software, automatically, as data is entered | a person or the computer at entry; the receiver after a transfer |
| Methods | range, format, length, presence, existence, limit, check digit | entry: visual check, double entry · transfer: parity byte, parity block, checksum |
| Lets through | a wrong value that still obeys the rules, such as 4057 for 4075 | an original that was itself wrong; the same mistake typed twice |
1 An age must be from 0 to 120. A form shows 71, but 17 was typed. Will a range check reject 17? Why?
2 Which method would catch it, and how?
3 Give one reason data can be wrong after both validation and verification.
- 1no: 17 is in range, so it is reasonable
- 2verification: a visual check against the form, or double entry
- 3the original document was itself wrong (or the same wrong value was entered twice, and it is valid)
Verification during data entry
Even a careful typist hits the wrong key now and then. Verification during data entry checks that what was typed matches the original. There are two methods. For each, say what is compared with what, and who compares.
Visual check
A person compares the screen with the original, character by character.
Double entry
The data is typed twice; the computer compares the two entries and asks again until they match.
DECLARE First, Second : STRING REPEAT OUTPUT "Enter the asset tag" INPUT First OUTPUT "Enter the asset tag again" INPUT Second IF First <> Second THEN OUTPUT "Entries differ: enter the tag again" ENDIF UNTIL First = Second OUTPUT "Accepted: ", First
Test run
Inputs: B4X92, B4X29, then B4X92 twice.
Enter the asset tag Enter the asset tag again Entries differ: enter the tag again Enter the asset tag Enter the asset tag again Accepted: B4X92
Two characters were swapped in the second entry, so the tag is typed again.
Compare the two methods
Who does the comparing decides what each method can miss.
| Visual check | Double entry | |
|---|---|---|
| Who compares | a person | the computer |
| What is compared | the entered data with the original document (on screen, or a printout) | two separate entries of the same data |
| Can miss | a difference the person overlooks; tiring for large amounts of data | the same mistake typed twice; takes twice as long to enter |
1 Run the pseudocode with the inputs C7K10, C7K01, C7K10, C7K10. How many times is “Entries differ” output?
2 A clerk types the same wrong tag twice. Which method misses this?
3 For each method, say who compares and what is compared with what.
- 1once: the first pair differs, the second pair matches and is accepted
- 2double entry: both entries match, so the wrong tag is accepted
- 3visual check: a person compares the entered data with the original document; double entry: the computer compares two entries of the same data
Validation checks
Software cannot tell whether a value is true, but it can catch one that breaks a rule. Validation is carried out by software as data is entered: data that breaks a rule is rejected before it is stored. An existence check is also called a look-up check.
The validation checks, each applied to a field
Each row: the check, its rule, a field it suits, and one value it accepts and one it rejects.
| Check | Rule it applies | Field and rule | Accepted ✓ / rejected ✗ |
|---|---|---|---|
| Range | a lower and an upper bound | Oven temperature: 150 to 250 | 180 ✓ · 270 ✗ |
| Limit | a single bound | Tickets per order: at most 6 | 4 ✓ · 9 ✗ |
| Presence | not left blank | Surname must be entered | "Osei" ✓ · "" ✗ |
| Length | number of characters in bounds | Password: 8 to 20 characters | "bluefinch42" ✓ · "cat5" ✗ |
| Format | a set pattern of characters | Locker code, e.g. L42-B | "L42-B" ✓ · "L4B" ✗ |
| Existence | one of the stored or allowed values | Shirt size: S, M or L | "M" ✓ · "XL" ✗ |
| Check digit | the recalculated digit matches | Member number: digit sum MOD 10 | "73583" ✓ · "73593" ✗ |
| Type | the expected data type | Quantity: a whole number | "7" ✓ · "7.5" ✗ |
| Check | Rule and examples |
|---|---|
| Range | a lower and an upper bound Oven temperature: 150 to 250 180 ✓ · 270 ✗ |
| Limit | a single bound Tickets per order: at most 6 4 ✓ · 9 ✗ |
| Presence | not left blank Surname must be entered "Osei" ✓ · "" ✗ |
| Length | number of characters in bounds Password: 8 to 20 characters "bluefinch42" ✓ · "cat5" ✗ |
| Format | a set pattern of characters Locker code, e.g. L42-B "L42-B" ✓ · "L4B" ✗ |
| Existence | one of the stored or allowed values Shirt size: S, M or L "M" ✓ · "XL" ✗ |
| Check digit | the recalculated digit matches Member number: digit sum MOD 10 "73583" ✓ · "73593" ✗ |
| Type | the expected data type Quantity: a whole number "7" ✓ · "7.5" ✗ |
One field, several checks: renewal date 18/09/2030
Each numbered check tests something different about the same date. A value can pass one check and fail another.
| Check | Applied to this field |
|---|---|
| Presence | the date cannot be left blank |
| Format | dd/mm/yyyy: two digits, /, two digits, /, four digits |
| Length | exactly 10 characters |
| Range | from 01/01/2030 to 31/12/2030, including both dates |
| Type | must be a valid DATE |
- 1Presence: the box cannot be left blank.
- 2Format: dd/mm/yyyy: two digits, /, two digits, /, four digits.
- 3Length: exactly 10 characters.
- 4Range: from 01/01/2030 to 31/12/2030, both dates included.
- 5Type: it must be a valid DATE.
Do not confuse
- Range has two bounds, limit has one: they do not count as two different methods in one answer. Apply each check to the field: “4 to 99”, not “checks the range”.
- Presence: something was entered. Existence: the value is one that is allowed or already stored.
- Format is the pattern; length is the number of characters.
1 A field holds a shirt size: S, M or L. Which check rejects “XL”?
2 Tickets per order: at most 6. Is this a range check or a limit check? Is 6 accepted?
3 Which check would reject the renewal date 18/9/2030, and why?
- 1existence (look-up): XL is not one of the allowed values
- 2a limit check (one bound); 6 is accepted
- 3format (and length): it has 9 characters, not the dd/mm/yyyy pattern of 10
Validation in pseudocode: name the check
Each program below rejects some inputs, but which check is it? Every validation check is an IF statement: read what the condition tests, not the message it outputs.
Checks on the value: bounds, blanks and lists
In each panel, find the IF line and read only its condition: how many bounds, an empty string, or a list.
DECLARE Score : INTEGER INPUT Score IF Score < 1 OR Score > 40 THEN OUTPUT "Rejected" ENDIF
DECLARE Tickets : INTEGER INPUT Tickets IF Tickets > 6 THEN OUTPUT "Too many tickets" ENDIF
DECLARE Surname : STRING INPUT Surname IF Surname = "" THEN OUTPUT "Enter a surname" ENDIF
DECLARE Size : STRING INPUT Size IF Size <> "S" AND Size <> "M" AND Size <> "L" THEN OUTPUT "No such size" ENDIF
Checks on the characters: format and length
These look at the characters of the input, not its value: one counts them with LENGTH, the other looks for a required character.
DECLARE Code : STRING DECLARE Pos, Hyphens : INTEGER INPUT Code Hyphens ← 0 FOR Pos ← 1 TO LENGTH(Code) IF MID(Code, Pos, 1) = '-' THEN Hyphens ← Hyphens + 1 ENDIF NEXT Pos IF Hyphens <> 1 THEN OUTPUT "Code needs one hyphen" ENDIF
DECLARE Code : STRING INPUT Code IF LENGTH(Code) < 5 OR LENGTH(Code) > 9 THEN OUTPUT "Code must be 5 to 9 characters" ENDIF
How to tell them apart
- Two bounds → range; one bound → limit.
= ""→ presence; a list of allowed values → existence.LENGTH()→ length; a pattern or required character → format.- A digit recalculated from the others → check digit.
- The data type is tested, e.g. a whole number → type check.
1 Name the check: IF Weight > 30 THEN
2 Name the check: IF Weight < 1 OR Weight > 30 THEN
3 Name the check: IF LENGTH(PostCode) <> 7 THEN
4 Name the check: IF Colour <> "Red" AND Colour <> "Blue" THEN
- 1limit: one bound
- 2range: two bounds
- 3length: it uses LENGTH()
- 4existence: the value must be one of a list
Score > 40 alone is a limit check; Score < 1 OR Score > 40 is a range check. When each answer must be a different method, do not name the same check twice.Check digits
One mistyped digit in a barcode could charge you for the wrong item. A check digit is an extra digit calculated from the other digits of a number, such as an ID or a barcode, and stored at the end. When the number is entered, the digit is recalculated and compared.
Method 1: sum of the digits MOD 10
Add the four digits, keep the remainder after dividing by 10, and append it. Then recalculate it for each entry: which mistake gets through?
| Entered | What happened | Sum → MOD 10 | Last digit | OK |
|---|---|---|---|---|
| 73583 | correct entry | 7+3+5+8 = 23 → 3 | 3 | ✓ |
| 73593 | one digit mistyped | 7+3+5+9 = 24 → 4 | 3 | ✗ |
| 37583 | first two digits swapped | 3+7+5+8 = 23 → 3 | 3 | ✓ |
Method 1 in pseudocode, and a weighted method
Work through the weighted sum first: each position has its own weight, so a swap changes the total. In the code, AddCheck builds the stored number and TestCheck recalculates the last digit.
Method 2: weighted sum MOD 11
Remainder 0 gives check digit 0; remainder 1 gives 10, written X.
Swap the first two digits: 1 × 5 + 6 × 4 + 8 × 3 + 3 × 2 = 59, giving check digit 7, not 2: rejected. Each position has its own weight, so swapped digits change the total.
AddCheck uses MOD and DIV · TestCheck uses a stringFUNCTION AddCheck(Code : INTEGER) RETURNS INTEGER DECLARE Sum, Rest : INTEGER Sum ← 0 Rest ← Code WHILE Rest > 0 Sum ← Sum + (Rest MOD 10) Rest ← Rest DIV 10 ENDWHILE RETURN Code * 10 + (Sum MOD 10) ENDFUNCTION FUNCTION TestCheck(Code : INTEGER) RETURNS BOOLEAN DECLARE Digits : STRING DECLARE Sum, Pos : INTEGER Digits ← NUM_TO_STR(Code) Sum ← 0 FOR Pos ← 1 TO LENGTH(Digits) - 1 Sum ← Sum + STR_TO_NUM(MID(Digits, Pos, 1)) NEXT Pos RETURN (Sum MOD 10) = STR_TO_NUM(RIGHT(Digits, 1)) ENDFUNCTION
1 Method 1: find the check digit for 4629 and write the stored number.
2 Method 1: is 52147 a valid number? Show the check.
3 Method 2 (weights 5, 4, 3, 2, then MOD 11): find the check digit for 2508.
- 14 + 6 + 2 + 9 = 21; 21 MOD 10 = 1; stored as 46291
- 25 + 2 + 1 + 4 = 12; 12 MOD 10 = 2, not 7: invalid
- 32 × 5 + 5 × 4 + 0 × 3 + 8 × 2 = 46; 46 MOD 11 = 2; 11 − 2 = 9
Parity check: adding a parity bit
Interference during transfer can flip a bit: a 0 arrives as a 1, or a 1 as a 0. A parity check adds one parity bit to each byte so that the receiver can tell when a bit has changed.
The sender sets the parity bit
Sender and receiver agree on odd or even parity. Count the 1s in the 7 data bits. Set the parity bit (here the rightmost bit, in blue) so the total, parity bit included, is even (even parity) or odd (odd parity).
1011001 · 4 ones
Even parity
10110010Odd parity
101100111101011 · 5 ones
Even parity
11010111Odd parity
11010110The receiver counts the 1s in each byte
Even parity. Sent: 10110010. Bits changed in transfer are shown in amber.
No error
101100104 ones · ✓ even: accepted
One bit flipped
101000103 ones · ✗ odd: error detected
Two bits flipped
111101106 ones · ✓ even: accepted, but the byte is wrong
The function counts the 1s and appends Ones MOD 2: 0 when the count is already even, 1 when it is odd.
FUNCTION AddEvenParity(Bits : STRING) RETURNS STRING DECLARE Ones, Pos : INTEGER Ones ← 0 Pos ← 1 WHILE Pos <= LENGTH(Bits) IF MID(Bits, Pos, 1) = '1' THEN Ones ← Ones + 1 ENDIF Pos ← Pos + 1 ENDWHILE RETURN Bits & NUM_TO_STR(Ones MOD 2) ENDFUNCTION
Limitations
- Detects any odd number of changed bits in a byte.
- If two bits change, the count keeps its parity: not detected.
- Shows that a byte is wrong, not which bit: the byte is sent again.
1 Add an even parity bit (rightmost) to the 7 data bits 0110100.
2 Add an odd parity bit to the same data bits.
3 Even parity is used. The byte 11010110 arrives. Is it accepted?
- 13 ones, so the parity bit is 1: 01101001
- 2parity bit 0: 01101000
- 3no: it has 5 ones, an odd number, so an error is detected and the byte is sent again
Parity block check
A parity bit shows that a byte is wrong, but not which bit. Checking the columns too pins the error down. Each byte has its own parity bit (horizontal parity). A parity byte, here the extra byte of column parity bits sent after the block, checks each column (vertical parity).
The sender builds the block
Read the grid two ways: across each byte for its parity bit P, then down each column for the parity byte.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | P | |
|---|---|---|---|---|---|---|---|---|
| Byte 1 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 |
| Byte 2 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 |
| Byte 3 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 |
| Byte 4 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| Parity byte | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
Odd parity reverses the rule: a byte whose 7 data bits hold an even number of 1s gets parity bit 1.
The receiver locates the error
Find the byte marked ✗ and the column marked ✗: the error is the bit where they cross.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | P | ||
|---|---|---|---|---|---|---|---|---|---|
| Byte 1 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | ✓ |
| Byte 2 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | ✓ |
| Byte 3 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | ✗ |
| Byte 4 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | ✓ |
| Parity byte | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | ✓ |
| column | ✓ | ✓ | ✓ | ✗ | ✓ | ✓ | ✓ | ✓ |
1 Even parity. Two bytes have the data bits 1100110 and 1010101. Give each byte with its parity bit.
2 Now give the parity byte for this two-byte block.
3 At the receiver, byte 2 and column 6 fail. What is wrong, and what does the receiver do?
- 111001100 and 10101010
- 201100110: with it, each column has an even number of 1s
- 3bit 6 of byte 2 has changed: the receiver flips it back, with no need to resend
Checksums, and choosing a check
Parity checks one byte or one column at a time. A checksum checks a whole block at once: it is one value worked out from the block with an agreed algorithm. It travels with the block, and the receiver works it out again to compare.
Follow the block from sender to receiver: one byte changes on the way, so the receiver’s result no longer matches 137.
Worked example: checksum = (sum of the bytes) MOD 256
Each row adds the four bytes and keeps the remainder after dividing by 256. The last row shows two changes that cancel out.
| Received | Bytes | Sum | MOD 256 | Compared with 137 |
|---|---|---|---|---|
| No error | 72 101 108 112 | 393 | 137 | ✓ matches: accepted |
| One byte changed | 72 100 108 112 | 392 | 136 | ✗ differs: error |
| Two changes cancel out | 72 100 109 112 | 393 | 137 | ✓ matches: error missed |
The data is the ASCII codes of “Help”. A checksum task names its algorithm (a plain sum, the sum MOD 256, or another calculation): use exactly the one given.
Which check, when?
All six checks in one place: be able to choose one for a situation and say whether it can find where the error is.
| Method | Used during | Detects an error | Can locate it |
|---|---|---|---|
| Visual check | data entry | by a person comparing with the original | the person sees where |
| Double entry | data entry | the two entries differ | no |
| Check digit | data entry (validation) | recalculated digit differs | no |
| Parity byte | data transfer | a byte has the wrong parity | no: the byte is resent |
| Parity block | data transfer | a byte or column has the wrong parity | yes, for one wrong bit |
| Checksum | data transfer | recalculated checksum differs | no: the block is resent |
1 The block 10, 200, 90 is sent with checksum = (sum of the bytes) MOD 256. What is the checksum?
2 The receiver gets 10, 201, 90 and the checksum you found. What does it do?
3 Which check can correct one wrong bit without a resend?
- 110 + 200 + 90 = 300; 300 MOD 256 = 44
- 2it recalculates 301 MOD 256 = 45; 45 ≠ 44, so it asks for the block again
- 3a parity block: the failing row and column locate the bit