Encryption and hashing
| English | Chinese | Pinyin |
|---|---|---|
| symmetric | 对称 | duì chèn |
| encryption | 加密 | jiā mì |
| asymmetric | 非对称 | fēi duì chèn |
| plaintext | 明文 | míng wén |
| ciphertext | 密文 | mì wén |
| decrypt | 解密 | jiě mì |
| key pair | 密钥对 | mì yào duì |
| public key | 公钥 | gōng yào |
| private key | 私钥 | sī yào |
| session key | 会话密钥 | huì huà mì yào |
| cryptographic hash | 密码散列 | mì mǎ sàn liè |
| digest | 摘要 | zhāi yào |
Two strangers agreeing a secret in public
- Here is a problem that sounds impossible. You and a shop have never met and share nothing. Everything you say to each other is overheard by everyone. Agree a secret key.
- Until 1976 the answer was that you cannot: symmetric encryption needs the key delivered in advance, by courier or in person, which is why wartime codebooks were printed and shipped.
- Then Diffie, Hellman and later Rivest, Shamir and Adleman showed it can be done, using a key that only locks and a different key that only unlocks. Every purchase you have ever made online rests on it.
- This lesson is symmetric 对称 and asymmetric 非对称 encryption, why real systems use both, and the one-way function called hashing.
The vocabulary
- Encryption 加密 turns readable plaintext 明文 into unreadable ciphertext 密文 using a key; to decrypt 解密 is to reverse it with the appropriate key.
- Encryption protects confidentiality: an intercepted copy cannot be understood. It does not stop the data being intercepted, delayed or deleted.
- The strength lies in the key, not in keeping the algorithm secret. The algorithms are published and studied precisely so that weaknesses are found by friends rather than enemies.
Symmetric encryption
- Symmetric encryption uses the same key to encrypt and to decrypt. AES is the standard example.
- It is fast, so it suits bulk data: a whole disk, a video stream, a large file.
- Its weakness is key distribution: the key must reach the other party without being intercepted, and if it is intercepted the whole scheme is broken. With $n$ people who all wish to talk privately in pairs, the number of keys needed grows with the square of $n$.
A shift cipher (symmetric key)
Caesar's cipher shifts every letter forward by a fixed key. The SAME key both encrypts and decrypts — that is what symmetric means. Try to read the ciphertext without knowing the shift.
Symmetric encryption uses:
Symmetric encryption shares one secret key — fast, but it must be distributed securely.
Asymmetric encryption
- Asymmetric encryption gives each user a key pair 密钥对: a public key 公钥 they publish to the world, and a private key 私钥 they never reveal.
- Anything encrypted with the public key can be decrypted only with the matching private key. So to send Alice a confidential message you encrypt with Alice's public key, and only Alice can read it.
- No prior key exchange is needed, which solves the problem the lesson opened with. The cost is that it is much slower, so it is not used for large amounts of data.

One key locks, the other unlocks, and only one of them is secret
Match each cryptographic tool to what it uses.
Symmetric is fast but needs key sharing; asymmetric solves that with a key pair; hashing is one-way; HTTPS combines them.
To send a confidential message to Alice using asymmetric encryption, you encrypt with:
Encrypting with the recipient's public key means only their matching private key can decrypt it.
Match each kind of encryption to its main weakness.
The hybrid scheme uses each to cover the other's weakness: asymmetric to deliver the key, symmetric to carry the data.
Worked example: send a confidential message
- Explain how asymmetric encryption lets Bob send a confidential message to Alice, even if they have never met. [3]
- Alice publishes her public key, which anyone may have, including an eavesdropper.
- Bob encrypts the message with Alice's public key. The ciphertext can only be decrypted by the matching private key.
- Alice decrypts it with her private key, which she has never shared. An eavesdropper holding the public key and the ciphertext cannot recover the message.
- The commonest error is saying Bob encrypts with his own key. Trace whose key is used at each step.
Bob sends Alice a confidential message using asymmetric encryption. Which key does he encrypt with?
Only Alice's private key can undo what her public key did, and only Alice has it. Bob never sees Alice's private key at all.
The hybrid approach, which is what really happens
- Symmetric is fast but cannot share its key; asymmetric can share a key but is slow. Real systems use each for what it is good at.
- The client generates a random session key 会话密钥, encrypts that small key with the server's public key, and sends it. The server decrypts it with its private key, and now both sides hold the same session key.
- Every byte of the actual conversation is then encrypted symmetrically with that session key: fast, and the slow asymmetric step happened only once, on a few bytes.
- This is exactly how HTTPS and SSH work.

Asymmetric to agree the key, symmetric to carry the data
In the hybrid approach used by HTTPS, asymmetric encryption is used to:
Slow asymmetric crypto just shares a session key; the bulk data then uses fast symmetric encryption.
Put the steps of the hybrid scheme used by HTTPS in order.
The slow asymmetric step runs once, on a few bytes; everything after it is fast symmetric encryption.
Hashing
- A cryptographic hash 密码散列 turns an input of any size into a fixed-size digest 摘要. The same input always gives the same digest, and a tiny change to the input changes the digest completely.
- It is one-way: the input cannot be recovered from the digest. That is the whole point, and it is what makes it different from encryption, which is designed to be reversed.
- Uses: storing passwords, where the system keeps only the digest and compares digests at login, so a stolen database yields no passwords; and checking integrity, where a file's digest is recomputed and compared to detect any change.
A cryptographic hash produces a fixed-size ____ from an input of any size.
The same input always gives the same digest, a small change gives a completely different one, and the input cannot be recovered from it.
Worked example: why hash a password instead of encrypting it
- A website stores users' passwords as hashes rather than as encrypted text. Explain why.
- Encryption is reversible: a key exists somewhere that turns the stored value back into the password, and an attacker who obtains the database may also obtain the key.
- Hashing is one-way, so a stolen database of digests does not yield the passwords, and even the site's own staff cannot read them.
- Login still works because the system hashes what the user typed and compares digests, never the passwords themselves.
Hashing and the avalanche effect
A hash is one-way: easy to compute, practically impossible to reverse. A tiny change in the input flips a large, unpredictable part of the output — the avalanche effect that makes hashes good for passwords.
A cryptographic hash is one-way (you cannot recover the input from the digest) and shows the avalanche effect — a tiny change in the input flips a large, unpredictable part of the output.
One-wayness plus avalanche is what makes hashes good for storing passwords and checking integrity.
Why store passwords as hashes rather than encrypted? Select all that apply.
A fixed-size digest may indeed be shorter, but that is not the security reason. Irreversibility is.
Marks that slip away
- To send someone a confidential message you use their public key, not yours. Say whose key at every step.
- Symmetric's weakness is key distribution; asymmetric's weakness is speed. The hybrid uses each to cover the other's.
- Hashing is one-way and is not encryption: there is no key and nothing to decrypt.
- Encryption protects confidentiality only. It does not stop interception, deletion, or a message being altered undetectably: for that you need a hash.
You've got it
- encryption turns plaintext into ciphertext with a key and protects confidentiality only; the strength is in the key, not in hiding the algorithm
- symmetric: one shared key, fast, good for bulk data, weak on key distribution · asymmetric: a public key to encrypt and a private key to decrypt, needs no prior exchange, but slow
- the hybrid used by HTTPS and SSH sends a random session key encrypted asymmetrically, then carries the data symmetrically
- a cryptographic hash makes a fixed-size digest, is one-way, and is used for passwords and integrity checks