5.6 Safe computing: encryptionLocking data so only the right person can read it

Cryptography is the study of keeping information secret. Encryption is the process of encoding data to prevent unauthorized access. Decryption is the process of decoding the data. A key is the secret piece of information that controls the encoding: with the right key, decryption is easy; without it, it should be practically impossible.
?Wait, what does MOD do?
Here's the oldest example in the book, the Caesar cipher. Number the letters A = 0 to Z = 25, and shift every letter forward by a key, say 3, wrapping around at the end with MOD 26. SAFE becomes VDIH, and Y wraps around to B. To decrypt, shift back by the same key. The same key both encrypts and decrypts, which makes this symmetric encryption.
| Letter | S | A | F | E | Y |
|---|---|---|---|---|---|
| Number (A = 0) | 18 | 0 | 5 | 4 | 24 |
| + 3, then MOD 26 | 21 | 3 | 8 | 7 | 1 |
| Encrypted letter | V | D | I | H | B |
1PROCEDURE shiftLetter(num, key)2{3 RETURN((num + key) MOD 26)14}5DISPLAY(shiftLetter(18, 3))6DISPLAY(shiftLetter(24, 3))7DISPLAY(shiftLetter(21, 23))2
- line 3 MOD 26 wraps past Z back to A
- line 7 shifting by 23 more is the same as shifting back 3
Symmetric key encryption involves one key for both encryption and decryption. Modern symmetric ciphers are far stronger than Caesar's, which has only 25 useful keys and can be cracked by trying them all. But they share its big problem: both people need the same secret key, so how do you get it to the other person without anyone seeing it? Over the internet, any message carrying the key could be intercepted.
Public key encryption, also called asymmetric encryption, solves that. It pairs a public key for encryption and a private key for decryption. The receiver publishes the public key for anyone to use and keeps the matching private key secret. The sender does not need the receiver's private key to encrypt a message, but the receiver's private key is required to decrypt it. So two strangers can communicate securely without ever meeting to share a secret.
One question is left: how do you know a public key really belongs to your bank, and not to an impostor? Certificate authorities issue digital certificates that validate the ownership of encryption keys used in secure communications, and they are based on a trust model: your browser trusts certain certificate authorities, so it trusts the keys they vouch for. That's part of what happens when you see https and a lock icon in the address bar. Beyond the course, as a bonus: the lock means the connection is encrypted and the certificate matches the site's name. It doesn't mean the site is honest; a phishing site can have a lock too.
?Wait, which key is the secret one?
I thought about it. Show me
- (a) M = 12, E = 4, E = 4, T = 19. Add 4: 16, 8, 8, 23. Letters: Q, I, I, X. MEET becomes QIIX.
- (b) L = 11, S = 18, A = 0. Subtract 4: 7, 14, and 0 − 4 = −4, which wraps around to 22. Letters: H, O, W. LSA decrypts to HOW.
Why?
Wrapping backward: −4 MOD 26 = 22, the same as adding 22. This is why the procedure shifts "forward by 26 minus the key" to decrypt. - Check by encrypting HOW with key 4: H(7) + 4 = 11 = L, O(14) + 4 = 18 = S, W(22) + 4 = 26 MOD 26 = 0 = A. It matches.
- (c) Weak: there are only 25 useful keys, so an attacker can try them all in seconds and look for the one that makes sense.
- Public key encryption never sends a secret key at all. The receiver shares only the public key, which can lock messages but can't unlock them, so intercepting it doesn't help an eavesdropper.
Why?
That is the CED's point: the sender doesn't need the receiver's private key, but the receiver's private key is required to decrypt.
Answer: (a) QIIX. (b) HOW. (c) Only 25 keys, so it can be cracked by trying them all. Public key encryption shares only a public key, which cannot decrypt, so no secret ever travels.
Stuck? Get a hint
- Turn letters into numbers first: A = 0, B = 1, and so on.
- For decryption, subtract the key. If you go below 0, add 26.
- For (c), how many different keys could an attacker try?
- AAlice's private key
- BAlice's public key
- CBob's private key
- DBob's public key
Show the answer
D. Alice encrypts with Bob's public key, which anyone may have. Only Bob's private key can decrypt it. Alice doesn't have Bob's private key, and a message locked with her own public key could only be opened by her.
- AIt encrypts every message sent on the internet
- BIt issues digital certificates that validate who owns an encryption key
- CIt stores everyone's private keys in a safe place
- DIt blocks phishing emails before they arrive
Show the answer
B. Certificate authorities vouch that a public key really belongs to a site or organization, using a trust model. They never hold your private key; nobody else should.
Say it out loud once: "lock with their public key, unlock with their private key." Every public key question on the exam is that sentence with names filled in.
- Encryption encodes data to prevent unauthorized access; decryption decodes it.
- Symmetric encryption: one key encrypts and decrypts. Hard part: sharing the key secretly.
- Public key encryption: encrypt with the receiver's public key, decrypt with the receiver's private key.
- Certificate authorities issue digital certificates that validate key ownership, based on a trust model.