Error checking and encryption
IGCSE Computer Science · Data Transmission
Why errors happen
Data can be corrupted during transmission by interference, by loss of signal over long distances, or by a break in the connection. So every transmission needs a way to detect that something has changed.
Parity check
One bit of each byte is reserved as the parity bit. It is set so that the total number of $1$s is even (even parity) or odd (odd parity), as agreed in advance.
Using even parity, to send $1011001$ the sender counts four $1$s — already even — so the parity bit is $0$, giving $01011001$.
The receiver counts the $1$s. If the count no longer matches the agreed parity, an error is detected.
Its critical weakness: if two bits change, the number of $1$s keeps the same parity, so the error is not detected at all. In general, parity only catches an odd number of changed bits.
It also cannot say which bit is wrong, only that something is wrong.
Checksum
A value is calculated from the data before sending and transmitted with it. The receiver recalculates the value from the data it received and compares.
If the two values differ, the data was corrupted and is requested again. A checksum is more reliable than a parity check because it depends on all the data, not just a count of bits.
Echo check
The receiver sends the data back to the sender, which compares it with the original. If they differ, the data is sent again.
Its weaknesses are worth stating: it doubles the traffic, and if a difference is found there is no way to know whether the error happened on the way out or on the way back.
Check digit
An extra digit is calculated from all the other digits and added to the end of a number. It is used on barcodes, ISBNs and bank account numbers.
When the number is entered or scanned, the digit is recalculated and compared — catching mistyped digits and, importantly, transposed digits (two digits swapped), which is one of the commonest human errors.
Automatic Repeat reQuest
ARQ uses acknowledgements and a timeout:
- the sender transmits a packet and starts a timer;
- if the packet arrives correctly, the receiver sends a positive acknowledgement;
- if no acknowledgement arrives before the timer runs out, the sender resends the packet;
- this repeats until the packet is acknowledged or a maximum number of attempts is reached.
Note what makes it different from the methods above: those only detect errors, while ARQ also corrects the situation by resending.
Encryption
Encryption scrambles data using a key so that anyone intercepting it cannot understand it. Plaintext becomes ciphertext.
| symmetric | the same key encrypts and decrypts. Fast, but the key itself must somehow be sent securely — which is the whole problem |
| asymmetric | a public key encrypts and a different private key decrypts. The public key can be shared openly because it cannot decrypt; only the private key can, and it never leaves the owner |
Note carefully what encryption does not do: it does not stop data being intercepted or stolen. It only makes the stolen data meaningless to whoever takes it.
Worked example: proving that a parity check misses a two-bit error
The sender uses even parity to send the byte $01011001$. (a) Confirm that the parity bit is set correctly. (b) Show what happens if one bit is changed on the way. (c) Show what happens if two bits are changed, and state the consequence.
Solution
(a) Confirm the parity bit.
Count the $1$ bits in $01011001$: the positions with a $1$ bit are the second, fourth, fifth and eighth — four $1$ bits in total.
Four is an even number, so this byte satisfies the even parity convention ✓
(b) If ONE bit is changed.
Suppose the first bit changes from $0$ to $1$, giving $11011001$.
The receiver counts five $1$ bits — an odd number. This does not match the even parity convention, so the receiver knows the data is corrupted and requests a resend.
The error is successfully detected.
(c) If TWO bits are changed.
Suppose the first bit changes from $0$ to $1$, and the second bit changes from $1$ to $0$, giving $10011001$.
The receiver counts: the first, fourth, fifth and eighth bits — still four $1$ bits, still even.
The byte matches the convention perfectly, so the receiver concludes the data is intact and accepts it.
The error slips through completely without anyone knowing.
Why this happens. Each time a bit changes, the parity flips. Changing one bit flips it once so it is different and is detected. Changing two bits flips it twice and it returns to how it was.
In general: a parity check only catches an error when the number of changed bits is odd.
Consequence. This is a serious limitation, because interference often corrupts several adjacent bits rather than just a single bit.
A parity check also does not tell you which bit is wrong, only that something is wrong.
That is why real systems use a checksum — it depends on all of the data so it is far more reliable — and combine it with automatic repeat request so that errors are not only detected but also corrected.
Worked example: why asymmetric encryption solves the key problem
Explain why symmetric encryption has a fundamental problem when two parties have never communicated before, and how asymmetric encryption solves it. State clearly what encryption does not do.
Solution
The problem with symmetric encryption.
Symmetric encryption uses the same key to encrypt and decrypt. That means the receiver must have exactly that key in order to read the message.
But if the two parties have never met, how can the key be sent?
- sending the key over the same channel → an eavesdropper can intercept the key and then decrypt everything afterwards;
- encrypting the key before sending it → that needs another key to do so, and the problem repeats exactly.
This is a vicious circle: to exchange securely you need a shared key, but to have a shared key you already need a secure channel.
How asymmetric encryption solves it.
It uses two different keys, mathematically linked to each other:
- the public key — used only to encrypt;
- the private key — used only to decrypt.
The key point: the public key cannot decrypt what it has just encrypted. So the receiver can publish the public key to the whole world without losing security.
Anyone who wants to send a message takes that public key and encrypts with it. Only the holder of the private key can open it, and the private key never leaves its owner's machine — so there is nothing to intercept.
The vicious circle is broken: no secret needs to be exchanged beforehand.
The cost. Asymmetric encryption is much slower than symmetric. In practice, systems often use asymmetric encryption only to securely exchange a symmetric key, and then use that symmetric key for the rest of the data — combining both security and speed.
What encryption does NOT do. It does not prevent data from being intercepted, copied or stolen.
An attacker can still obtain exactly those bytes. Encryption only ensures that those bytes are meaningless to them.
This is a point that is often written wrongly, and an answer saying encryption “stops hackers getting the data” is inaccurate.