Lesson 60: Symmetric encryption
Lock it with a key
- Encryption turns readable plain text into cipher text that means nothing to anyone without the key.
- Symmetric encryption uses the same key to encrypt and to decrypt.
- Here the key is a number and the rule is XOR. Lesson 38 used a Caesar shift as the key; this rule works on the bits.
Words for this lesson
| Word | Meaning |
|---|---|
| plain text | the readable message |
| cipher text | the encrypted message |
| key | the secret value used to encrypt and decrypt |
| symmetric | one key for both encrypting and decrypting |
XOR with the key, bit by bit
| Bits | Value | |
|---|---|---|
| S | 0101 0011 | 83 |
| key | 0010 1010 | 42 |
| XOR | 0111 1001 | 121 (79 hex) |
- XOR the result with the key again and you get 0101 0011: S is back.
In the exam
- 0478/12/M/J/24 Q2(c): (i) explain how data is encrypted using symmetric encryption. Mark scheme: data is encrypted and decrypted with the same key; plain text is encrypted into cipher text by an algorithm that uses the key; the key is sent to the receiver. (ii) Why encrypt? To keep the data secure: it is meaningless if it is intercepted.
- The weak point of symmetric encryption is the key: if someone gets it on the way, they can decrypt everything. Asymmetric encryption uses two keys (public and private) to solve this.
Kesulitan 3/5 · 200 koin + bonus kecil pada penyelesaian pertama hari ini
Encrypt a message with a secret key. The key is 42. For each character, XOR its code with the key: text[i] ^ KEY. The program prints the cipher text as hexadecimal. Type SECRET: the cipher text is 79 6F 69 78 6F 7E.
Klik Jalankan untuk melihat output di sini.
Kesulitan 4/5 · 280 koin + bonus kecil pada penyelesaian pertama hari ini
Now be the receiver. The cipher text arrives in hex, and the program turns each pair into a number, code. Decrypt it with the same key: XOR the code with 42 again, and add the character to plain. Type 79 6F 69 78 6F 7E: the program prints Plain: SECRET.
Klik Jalankan untuk melihat output di sini.