HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Encryption: Symmetric and Asymmetric Keys
  1. 1Why we encrypt data
  2. 2Symmetric encryption
  3. 3Asymmetric encryption: public and private keys
  1. Computer Science
  2. /Encryption: Symmetric and Asymmetric Keys
  3. /Symmetric encryption

Course 2.3·Lesson 2 of 3

Symmetric encryption

Symmetric encryption uses one key to lock and the same key to unlock. This lesson shows how it works, why both sides need the same secret key, and the weakness this brings: the key itself has to reach the receiver safely.

about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
Encryption: Symmetric and Asymmetric Keys
  1. 1Why we encrypt data
  2. 2Symmetric encryption
  3. 3Asymmetric encryption: public and private keys

Try the code and the simulations beside the lesson.

One key for both jobs

Think of a padlocked box with one key. You lock a letter in the box and post it. Your friend needs a copy of the same key to open it. That is symmetric encryption.

In symmetric encryption the same key is used to encrypt the plaintext and to decrypt the ciphertext.

Symmetric encryption. The sender encrypts plaintext with a key into ciphertext, the ciphertext crosses the network, and the receiver decrypts it with the same key, drawn as an identical key icon on both sides. A dashed arrow shows that the key itself must also be shared between sender and receiver, and a warning marks that the key can be intercepted on that path.
  1. The sender and the receiver agree on a secret key.
  2. The sender encrypts the plaintext with the key, and sends the ciphertext.
  3. Anyone who intercepts the ciphertext cannot understand it without the key.
  4. The receiver decrypts the ciphertext with the same key, and gets the plaintext back.

The shift cipher of the last lesson is symmetric: the key 333 locks, and the same key 333, used backwards, unlocks.

The weakness: sharing the key

Both sides need the same key. So, at some point, the key must be sent or given to the receiver. If someone intercepts the key on its way, they can decrypt every message sent with it. Keeping the key secret while sharing it is the main problem of symmetric encryption.

There is a second problem when many people talk. Each pair of people needs its own key, or else one person could read messages meant for others. With 444 people there are 666 pairs, so 666 keys. With more people the number of keys grows quickly, and each one must be shared safely.

Why real keys are long

A thief who does not know the key could try every possible key. This is called a brute-force attack. The shift cipher has only 252525 useful keys, so this takes no time at all.

Real keys are numbers made of many bits. A key of nnn bits has 2n2^n2n possible values. Each extra bit doubles the number of keys. With a key of hundreds of bits, trying every key would take far longer than the age of the Universe. The exam does not ask about key lengths, but this is why long keys are used.

Practise with new numbers

Try it in Python

The program plays the thief. It takes an intercepted message made with a shift cipher and tries every key until a real word appears. Then it prints how many keys there are for longer keys.

Read it first. Then run it. Which key did the sender use?

1. Encrypt your own message with key 11 (use the program of the last lesson) and put it in intercepted. Change "THIS" to a word in your message. Does the thief find it?

2. Add 128 to the list of bits. How many digits does the number of keys have?

Common mistakes

  • Saying symmetric encryption uses two keys. It uses one key, the same for encrypting and decrypting.
  • Forgetting the key must be shared. The receiver needs the same key, so it must reach them safely.
  • Saying a longer key makes the message longer. It makes the number of possible keys bigger, so guessing the key is harder.

Remember these

  • Symmetric encryption: the same key encrypts and decrypts.
  • The key must be shared between sender and receiver, and if it is intercepted, the data can be read.
  • A key of nnn bits has 2n2^n2n possible values.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. How many keys does symmetric encryption use for one message?
  1. What is the main weakness of symmetric encryption?
  1. How many different keys does a key of 101010 bits allow?
  1. Five friends each want a separate symmetric key with every other friend. How many keys are needed?
  1. Why is a brute-force attack on a shift cipher so easy?

Enroll free in Encryption: Symmetric and Asymmetric Keys

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (4)

A symmetric encryption system uses keys made of bits…Easy · High School (9–10) · by StemPy Lab
A thief tries to break a message encrypted with a 40-bit symmetric key…Medium · High School (9–10) · by StemPy Lab
Five members of a project team each want to send private messages to every other member, using…Medium · High School (9–10) · by StemPy Lab
Next: lesson 3Asymmetric encryption: public and private keys
← Encryption: Symmetric and Asymmetric Keys
← Why we encrypt dataAsymmetric encryption: public and private keys →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.

A class of 20 students wants every student to be able to send a private message to every other…Hard · High School (9–10) · by StemPy Lab

Python Labs (1)

A shift cipher with one shared keyPython Lab · by StemPy Lab