A levels Computer Science · Data representation
Encryption
1Why encrypt?
Encryption turns readable plaintext into unreadable ciphertext using an algorithm (a cipher) and a key. Only someone with the right key can decrypt it.
Encryption does not stop data being intercepted; it stops the interceptor understanding it. It protects passwords, online banking, messages and stored files.
Check yourself
What does encryption prevent?
Show the answer
An interceptor understanding the data
Unreadable, not unreachable.
2The Caesar cipher
The Caesar cipher shifts every letter a fixed number of places along the alphabet. The shift is the key.
Shift of 3
- H → K, E → H, L → O, L → O, O → R.
- HELLO becomes KHOOR.
It is very easy to break:
- there are only 25 possible keys, so all can be tried (brute force);
- frequency analysis: the most common letter in English is E, so the most common letter in the ciphertext is probably E.
Check yourself
Encrypt CAT with a Caesar shift of 2.
Show the answer
ECV
Each letter +2.
3The Vernam cipher
The Vernam cipher (one-time pad) combines each bit of the plaintext with a bit of the key using XOR.
XOR with a key
- Plaintext 'A' = 0100 0001. Key = 0011 0101.
- XOR (1 if the bits differ): 0111 0100.
- Decrypt: 0111 0100 XOR 0011 0101 = 0100 0001 = 'A'. The same key undoes it.
The Vernam cipher has perfect security, provided the key is:
- truly random;
- at least as long as the message;
- used only once, then destroyed.
Every possible plaintext of that length is equally likely, so even unlimited computing power cannot break it. Its weakness is sharing such long keys securely.
Check yourself
What makes the Vernam cipher unbreakable?
Show the answer
A truly random key, as long as the message, used only once
One-time pad.
4Symmetric and asymmetric encryption
| Symmetric | Asymmetric (public key) |
|---|---|
| the same key encrypts and decrypts | a public key encrypts; only the matching private key decrypts |
| fast | slower |
| the key must be shared secretly first | the public key can be given to anyone |
| example: AES | example: RSA |
In practice they are combined: asymmetric encryption is used to swap a symmetric key securely, then the fast symmetric key encrypts the rest of the conversation (this is how HTTPS works).
Check yourself
What is the main problem with symmetric encryption?
Show the answer
The key has to be shared securely before use
Key distribution.
5Public keys and digital signatures
Public-key encryption. Anyone can lock a message with Bob's public key, but only Bob's private key can unlock it.
A digital signature proves who sent a message and that it has not been changed:
- The sender makes a hash (a short fingerprint) of the message.
- The sender encrypts the hash with their private key: this is the signature.
- The receiver decrypts the signature with the sender's public key, hashes the message themselves, and compares.
- If the hashes match, the message is genuine and unchanged.
A digital certificate, issued by a trusted certificate authority, links a public key to its owner, so you know a website's public key really belongs to that website.
Check yourself
Which key does the sender use to create a digital signature?
Show the answer
Their own private key
Only the sender has it.
6Hashing
A hash function turns data of any length into a fixed-length value. It is one-way: you cannot work back from the hash to the data.
- Passwords are stored as hashes. When you log in, your typed password is hashed and compared, so the real password is never stored.
- A salt (random data added before hashing) means two users with the same password get different hashes, which defeats pre-computed tables of common passwords.
- Hashes also check that downloaded files have not been changed.
Hashing is not encryption: encryption can be reversed with the key, but a hash cannot be reversed.
Check yourself
Why are passwords stored as hashes rather than encrypted?
Show the answer
A hash cannot be reversed, so a stolen database does not reveal the passwords
One-way.
Now test yourself
This lesson has a 8-question quiz and 5 exam-style questions with mark schemes in Impera. Free, with your progress saved.
Practise in Impera