Encryption scrambles data so that only someone with the correct key can read it. The original readable data is plaintext, the scrambled result is ciphertext, and the method used is the encryption algorithm. You may be asked to define these, explain why encryption is used, and trace a simple example.
This lesson follows how a browser and server communicate and sits within the internet security module.
Why is data encrypted?
Data sent across a network passes through several devices that the sender does not control.
Encryption means that if the data is intercepted, it cannot be understood without the key. It protects confidentiality. It does not stop the data being copied or deleted.
HTTPS uses encryption between browser and server, which is why a page address that starts with https is safer to send a password through than one that starts with http.
What are symmetric and asymmetric encryption?
- Symmetric: one key both encrypts and decrypts. It is fast, but the sender and receiver must share the key without anyone else seeing it.
- Asymmetric: a public key encrypts and a matching private key decrypts. Anyone may have the public key. Only the owner holds the private key, so no secret key has to be sent.
A traced example: the shift cipher
A shift (Caesar) cipher moves each letter along the alphabet by a number, the key. Letters are numbered A = 0, B = 1, … Z = 25. Wrapping round uses MOD 26.
FUNCTION Shift(Letter : CHAR, Key : INTEGER) RETURNS CHAR
Pos <- ASC(Letter) - 65
NewPos <- (Pos + Key) MOD 26
RETURN CHR(NewPos + 65)
ENDFUNCTION
Here ASC('A') is 65, so subtracting 65 gives a position from 0 to 25.
Worked example. Encrypt CAT with key 3.
| Letter | ASC | Pos | Pos + 3 | MOD 26 | CHR(+65) |
|---|---|---|---|---|---|
| C | 67 | 2 | 5 | 5 | F |
| A | 65 | 0 | 3 | 3 | D |
| T | 84 | 19 | 22 | 22 | W |
The ciphertext is FDW. To decrypt, subtract the key instead: F is 5, 5 − 3 = 2, which is C.
Check the wrap-round with X and key 3: ASC is 88, Pos = 23, 23 + 3 = 26, and 26 MOD 26 = 0, which gives A. The alphabet wraps from Z back to A.
The mistake to watch for
Mistaken answer: “Encryption stops hackers getting the data.”
The student claimed prevention of interception.
Encryption does not stop interception. It makes the intercepted data unreadable without the key. Say what the intruder is left with: ciphertext.
A second slip in tracing is forgetting MOD 26. Encrypting X with key 3 without it gives 26, which is not a letter position.
Check yourself
1. Encrypt ZOO with a shift key of 5. Show Pos values.
Show answer
Z = 25, 25 + 5 = 30, 30 MOD 26 = 4, so E. O = 14, 14 + 5 = 19, so T. Second O also T. Ciphertext: ETT.
2. Decrypt MJQQT, which was encrypted with key 5.
Show answer
Subtract 5 from each position: M(12) to 7 = H, J(9) to 4 = E, Q(16) to 11 = L, Q to L, T(19) to 14 = O. The plaintext is HELLO. Check: HELLO shifted by 5 gives MJQQT.
3. In asymmetric encryption, which key does a user keep secret?
Show answer
The private key. The public key can be shared with anyone.
Where does this lead next?
Encryption protects data in transit, but users can still be tricked into giving it away, as spotting phishing signals shows. Practise with the mixed practice set and the restricted pseudocode trace trainer, which suits the shift cipher trace.
If tracing algorithms is where you lose marks, working through them with a teacher is a good use of time in online one-to-one Computer Science tuition.