Skip to content

Beginner · Systems and cryptography · topic 14 of 43 · 35 min

Symmetric and asymmetric encryption

Explanation

Encryption scrambles data so only someone with the right key can read it. Symmetric encryption (like AES) uses one shared key and is fast. Asymmetric encryption (like RSA or elliptic curves) uses a public key and a private key, which solves the problem of sharing keys and makes digital signatures possible. Real systems such as HTTPS use both together.

Why encryption

Data travels over networks you do not control and sits on disks that can be stolen. Encryption turns readable data (plaintext) into scrambled data (ciphertext) using a key. Without the key, the ciphertext is useless. This protects confidentiality, both in transit (moving over a network) and at rest (stored on a disk).

An old idea: the Caesar cipher

The Caesar cipher shifts every letter by a fixed number. With a shift of 3, A becomes D and B becomes E. The key is the number 3. It is easy to understand and trivially easy to break: there are only 25 possible shifts, so an attacker tries them all. It is useful only to learn the words key, plaintext and ciphertext.

python
def caesar(text, shift):
    out = ""
    for ch in text:
        if ch.isupper():
            out += chr((ord(ch) - 65 + shift) % 26 + 65)
        elif ch.islower():
            out += chr((ord(ch) - 97 + shift) % 26 + 97)
        else:
            out += ch
    return out

secret = caesar("Meet at Gate 4", 3)
print(secret)
print(caesar(secret, -3))
Shows "Phhw dw Jdwh 4", then the original again. A toy, never for real secrets.

Symmetric encryption: one shared key

In symmetric encryption, the same key locks and unlocks. Modern symmetric ciphers like AES (Advanced Encryption Standard) with 128- or 256-bit keys are very fast and, used correctly, unbreakable in practice. AES protects BitLocker disks, Wi-Fi (WPA2/WPA3), VPN tunnels and the data part of every HTTPS connection.

A simple building block inside many ciphers is XOR (exclusive or). XOR-ing data with a key scrambles it; XOR-ing again with the same key gives the data back. On its own, a short repeating XOR key is weak and easy to break, but it shows the "same key both ways" idea.

The big problem with symmetric encryption is key sharing: how do two people who have never met agree on a secret key over an open network, without anyone listening learning it?

Asymmetric encryption: a key pair

Asymmetric (public-key) cryptography uses two keys that belong together. The public key can be shared with anyone. The private key is kept secret. What one key locks, only the other can unlock. Common algorithms are RSA and elliptic-curve cryptography (ECC), such as ECDSA and Ed25519.

Think of it like this: A public key is like an open padlock you hand out to everyone. Anyone can snap it shut on a box addressed to you, but only your private key opens it. Handing out padlocks does not risk your key.
  • Encrypting to someone: use their public key; only their private key decrypts.
  • Digital signature: the sender signs with their own private key; anyone can verify with the sender's public key. This proves who sent it (authenticity) and that it was not changed (integrity), and the sender cannot deny it (non-repudiation).
  • Key exchange: methods like Diffie-Hellman (and its elliptic-curve form, ECDHE) let two sides agree on a shared secret over an open network.

Hybrid encryption: using both

Asymmetric cryptography is slow, so real systems combine both. In HTTPS, asymmetric cryptography proves the server's identity (certificate and signature) and agrees on a fresh symmetric key (ECDHE). Then fast AES or ChaCha20 encrypts the actual data. Signal, WhatsApp, VPNs and SSH work in a similar way.

SymmetricAsymmetric
KeysOne shared secret keyPublic key + private key
SpeedFastSlow
ExamplesAES, ChaCha20RSA, ECC (ECDSA, Ed25519), ECDHE
Used forBulk data: disks, Wi-Fi, HTTPS dataKey exchange, signatures, certificates

Common mistakes

  • Inventing your own encryption. Always use well-known, tested libraries and algorithms.
  • Hard-coding keys in source code or pushing them to GitHub. Use a secrets manager.
  • Sharing a private key, or emailing it. A private key should never leave its owner.
  • Confusing encoding with encryption. Base64 only changes the format; anyone can decode it.
Tip: Quantum computers could one day break RSA and today's elliptic curves. NIST published its first post-quantum cryptography standards in August 2024 (FIPS 203, 204 and 205), and big browsers and messengers have started adding them.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Symmetric and asymmetric encryption · 1/7

Plaintext + key → ciphertext

Encryption turns plaintext into ciphertext with a key. Without the key, it is useless.

Prefer a video by a teacher? Find free videos on “symmetric vs asymmetric encryption explained public key private key” on YouTube ↗

In real life: Signing GST and company filings

In India, company directors and professionals sign filings on government portals with a Digital Signature Certificate (DSC), often on a USB token. The private key stays inside the token. When they sign, the portal checks the signature using the public key in the certificate. That proves who signed and that the document was not changed after signing, which is why a signed filing cannot be easily denied later.

Practice (0/4 done)

Task 1 · Code · Python

Write caesar(text, shift) that shifts upper-case and lower-case letters by shift places (wrapping Z to A) and leaves every other character unchanged. A negative shift decrypts.

Task 2 · Code · Python

Write xor_bytes(data, key) that XORs each byte of data with the key, repeating the key as needed (byte i uses key[i % len(key)]). Return bytes. XOR-ing twice with the same key must give the original back.

Task 3 · Question

Asha wants to send Ravi a secret file using asymmetric encryption. Which key should she encrypt it with?

Task 4 · Question

Why is the Caesar cipher insecure?

Quick quiz

Question 1

1.Which is a symmetric algorithm?

Question 2

2.A digital signature is created with…

Question 3

3.Why does HTTPS use both kinds of encryption?

Question 4

4.Base64-encoded text is…

Question 5

5.What should you never share?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Which is a symmetric algorithm?

Answer: AES

AES uses one shared key for both encryption and decryption.

A digital signature is created with…

Answer: The sender's private key

Sign with your private key; others verify with your public key.

Why does HTTPS use both kinds of encryption?

Answer: Asymmetric for identity and key agreement, symmetric for fast bulk encryption

Hybrid encryption combines the strengths of both.

Base64-encoded text is…

Answer: Just encoded: anyone can decode it

Encoding changes format only; there is no key.

What should you never share?

Answer: Your private key

Whoever has your private key can sign and decrypt as you.

In envelope encryption, what does the master key in KMS encrypt?Related

Answer: The data key

The data key encrypts the data; the master key encrypts the data key and never leaves KMS.

From Encryption, keys and secrets

Which encryption does WPA2 use?Related

Answer: AES-CCMP

WPA2 uses AES with CCMP.

From Wi-Fi security: WPA2, WPA3 and guest networks

What is a hybrid cloud?Related

Answer: On-premises or private systems working together with a public cloud

Hybrid joins your own systems with a public cloud.

From Public, private, hybrid and multi-cloud

A certificate's private key was leaked. What should happen?Related

Answer: Revoke the certificate and issue a new one with a new key

Revocation tells clients not to trust the old certificate.

From Certificates and PKI

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 1 more topic in “Systems and cryptography” before its exam: Certificates and PKI.
  2. Module 3 exam: Systems and cryptography · 12 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Identity and network defence. 43 topics left in the course before the final exam.

← Previous: Hashing: fingerprints for data