Symmetric encryption
Locking with a key
- Encryption scrambles a message so only someone with the key can read it.
- In symmetric encryption, the same key locks and unlocks. Sender and receiver must both know it.

The Caesar cipher
- The oldest example: shift every letter forward by a fixed number. With shift 3,
a → d,b → e, and so on. - The key is the shift. Decrypting just shifts back.
text = "attack"
shift = 3
out = "".join(chr((ord(c) - 97 + shift) % 26 + 97) for c in text)
print(out) # dwwdfn
Why Caesar is weak
- There are only 25 possible shifts, so a computer can try them all in a blink.
- This is a brute-force attack on the key — exactly what real encryption must resist.
What real ciphers do
- Modern symmetric ciphers like AES use 128-bit or longer keys: 2¹²⁸ is about 3 × 10³⁸ possible keys, far too many to try one by one.
- The big problem they leave: how do two people share the secret key safely? The next lesson solves it.
Covers: IGCSE 2.3 (symmetric encryption), A-Level 17.1.
Common mistakes
- One shared key both encrypts and decrypts.
- The hard part is sharing that key safely.
Criptografia simétrica
The Caesar cipher uses one shared key to encrypt and decrypt.
Dificuldade 3/5 · Moedas 200 + pequeno bônus na primeira conclusão hoje
Encrypt hello with a Caesar cipher: shift each letter forward by shift places (wrapping past z back to a). Build the encrypted string and print it.
Clique em Executar para ver a saída aqui.
Dificuldade 3/5 · Moedas 200 + pequeno bônus na primeira conclusão hoje
Now break it — that is why Caesar is weak. You intercepted cipher, and you suspect the plaintext is attack. Try every shift from 1 to 25, shifting para trás, and print the shift that turns cipher em attack.
Clique em Executar para ver a saída aqui.
Dificuldade 3/5 · Moedas 200 + pequeno bônus na primeira conclusão hoje
The receiver knows the key, so they can undo the shift. Write decrypt(text, shift), which moves each lowercase letter para trás by shift (wrapping from a back to z) and leaves spaces and other characters unchanged.
Clique em Executar para ver a saída aqui.