Lesson 38: Secret messages
Hide the message
- When data travels from one device to another, someone could read it on the way.
- Encryption changes the message so that it means nothing without the key.
- Julius Caesar did it 2000 years ago: move every letter 3 places along the alphabet. Your Arduino can do it in a millisecond.
Words for this lesson
| Word | Meaning |
|---|---|
| plain text | the message you can read |
| cipher text | the encrypted message |
| key | the secret number that locks and unlocks |
| encrypt / decrypt | lock / unlock the message |
The Caesar cipher with key 3
| Plain | A | B | C | X | Y | Z |
|---|---|---|---|---|---|---|
| Cipher | D | E | F | A | B | C |
- To decrypt, move back 3 places: D → A, A → X.
Letters are numbers
void setup() {
Serial.begin(9600);
char c = 'A';
Serial.println((int)c);
c = c + 3;
Serial.println(c);
}
void loop() {
}
- The Monitor shows 65, then D: 'A' is stored as 65 (ASCII), so 'A' + 3 is 68, which is 'D'.
In the exam
- 0478/12/M/J/24 Q2(c): (i) Explain how data is encrypted using symmetric encryption. The mark scheme's points, in your cipher: the same key encrypts and decrypts; plain text is turned into cipher text by an algorithm that uses the key; the key must be sent to the receiver. (ii) Why encrypt? To keep the data secure: without the key it is meaningless.
- A real cipher uses a much longer key than 3: with only 26 possible keys, a thief can try them all.
Dificuldade 4/5 · Moedas 280 + pequeno bônus na primeira conclusão hoje
Type a message in capital letters into the Serial Monitor. The board encrypts it with a Caesar cipher: each letter moves KEY (3) places along the alphabet, so A becomes D and HELLO becomes KHOOR. After Z it starts again at A: use % 26. Print Cipher: and the encrypted text. Other characters, like spaces, stay as they are.
Clique em Executar para ver a saída aqui.
Dificuldade 4/5 · Moedas 280 + pequeno bônus na primeira conclusão hoje
Now the other side: the receiver has the same key and turns the cipher text back into plain text. Move each capital letter KEY places back. Careful: A − 3 must give X, so add 26 before % 26. Print Plain: and the text.
Clique em Executar para ver a saída aqui.