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. /Asymmetric encryption: public and private keys

Course 2.3·Lesson 3 of 3

Asymmetric encryption: public and private keys

Asymmetric encryption uses two different keys: a public key that anyone may have, and a private key that only its owner has. This lesson shows how the pair works, which key is used for what, and why it solves the problem of sharing a secret key.

about 25 min1 simulation1 practice question
Lesson 3 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.

Two keys that belong together

Think of a letter box in a front door. Anyone can push a letter through the slot. But only the person with the door key can open the box and read the letters. Asymmetric encryption works like that.

Each person has a key pair: two keys that are made together and belong together.

  • The public key can be given to anyone. It is used to encrypt data for its owner.
  • The private key is kept secret by its owner and never shared. It is used to decrypt the data.

Data encrypted with a public key can only be decrypted with the matching private key. The public key cannot decrypt it, so it does not matter who has the public key.

Sending a message with asymmetric encryption

Asymmetric encryption from Sam to Lina. Lina sends her public key to Sam. Sam encrypts the plaintext with Lina's public key into ciphertext, which crosses the network. Eve intercepts the ciphertext and has the public key but cannot decrypt. Lina decrypts the ciphertext with her private key, which never leaves her.

Sam wants to send a private message to Lina.

  1. Lina has a key pair. She sends her public key to Sam. It does not matter if someone else sees it.
  2. Sam encrypts the message with Lina's public key.
  3. Sam sends the ciphertext. Eve intercepts it, but she cannot decrypt it, even though she may also have Lina's public key.
  4. Lina decrypts the ciphertext with Lina's private key, which only she has.

To reply, Lina uses Sam's public key, and Sam decrypts with Sam's private key. Always use the receiver's keys.

Why this solves the key problem

In symmetric encryption, a secret key has to travel from one person to the other. In asymmetric encryption, no secret key ever travels. Only public keys are sent, and they are no use for decrypting. The private keys never leave their owners.

It also needs fewer keys in a group. Each person needs just one key pair, however many people they talk to.

A toy model of a key pair

How can one key lock and a different key unlock? Real methods use very large numbers, hundreds of digits long. The simulation and the program below use tiny numbers just to show the idea. The exam does not ask for this calculation. In the toy model, a message number mmm is locked as c=m3 mod 33c = m^3 \bmod 33c=m3mod33 with the public key, and unlocked as c7 mod 33c^7 \bmod 33c7mod33 with the private key.

Practise with new numbers

Try it in Python

The program locks a short message, written as numbers, with the toy public key. It shows that locking again with the public key does not undo it, and that the private key brings the message back.

Read it first. Then run it. Which line gets the message back?

1. Change message to the numbers of your own initials (A = 1, B = 2, and so on). Does the private key still bring them back?

2. Change private = 7 to private = 5. What happens? Why must the two keys be a matched pair?

Common mistakes

  • Encrypting with the private key when sending a secret message. Use the receiver's public key.
  • Using your own public key to send to someone else. Use the receiver's public key.
  • Saying the public key must be kept secret. Anyone may have it. Only the private key is secret.
  • Saying the public key can decrypt. Only the matching private key can.

Remember these

  • Asymmetric encryption uses a public key and a private key, a matched pair.
  • Encrypt with the receiver's public key; the receiver decrypts with their private key.
  • No secret key has to be sent, so intercepting the public key does not help an attacker.

Check yourself

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

  1. Which key of a pair can be given to anyone?
  1. Omar wants to send an encrypted file to Mei. Whose public key does he use?
  1. An attacker has Mei's public key and intercepts the file. Can the attacker read it?
  1. Give one advantage of asymmetric encryption over symmetric encryption.
  1. In a class of 252525 students, each student has a key pair. How many keys are there in all, and how many are secret?

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 (3)

A company has 12 staff, and each has an asymmetric key pair…Easy · High School (9–10) · by StemPy Lab
This is a toy model with tiny numbers. The exam does not ask for this calculation…Medium · High School (9–10) · by StemPy Lab
A teacher wants each of her 30 students to be able to send her a private message that no other…Hard · High School (9–10) · by StemPy Lab
That was the last lessonBack to the course: take the test
← Encryption: Symmetric and Asymmetric Keys
← Symmetric encryptionNext →

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.

Python Labs (1)

A toy key pairPython Lab · by StemPy Lab

Question Sets (1)

Encryption: Think It Through10 questions · by StemPy Lab

Notes (1)

Encryption: Quick RevisionNote · by StemPy Lab