📖 Scenario: You are learning how computers keep messages safe when sending them over the internet. One way to do this is by using a special method called RSA encryption. This method uses two keys: one to lock (encrypt) the message and one to unlock (decrypt) it.Imagine you want to send a secret message to a friend. You will use your friend's public key to lock the message, and only your friend can unlock it with their private key.
🎯 Goal: Build a simple step-by-step understanding of how RSA encryption works by creating the keys, setting up a message, encrypting it, and then decrypting it.
📋 What You'll Learn
Create variables for the public and private keys with exact values
Set up a message variable with a specific text
Show how the message is encrypted using the public key
Show how the encrypted message is decrypted using the private key
💡 Why This Matters
🌍 Real World
Asymmetric encryption like RSA is used every day to protect emails, online shopping, and private chats by making sure only the right person can read the message.
💼 Career
Understanding RSA encryption is important for jobs in cybersecurity, software development, and network administration where protecting data is critical.
Progress0 / 4 steps
1
Create RSA keys
Create two variables called public_key and private_key. Set public_key to the string 'public123' and private_key to the string 'private456'.
Computer Networks
Hint
Think of public_key as the lock anyone can use, and private_key as the secret key only the owner has.
2
Set up the message
Create a variable called message and set it to the string 'Hello, friend!'.
Computer Networks
Hint
This is the secret message you want to send safely.
3
Encrypt the message
Create a variable called encrypted_message and set it to the string 'encrypted_with_public123' to represent the message encrypted using the public_key.
Computer Networks
Hint
This shows the message locked with the public key.
4
Decrypt the message
Create a variable called decrypted_message and set it to the string 'Hello, friend!' to represent the message decrypted using the private_key.
Computer Networks
Hint
This shows the original message unlocked with the private key.
Practice
(1/5)
1. What is the main purpose of the private key in RSA asymmetric encryption?
easy
A. To share with anyone for secure communication
B. To encrypt messages for everyone to read
C. To decrypt messages encrypted with the public key
D. To generate the public key
Solution
Step 1: Understand RSA key roles
In RSA, the public key encrypts data, and the private key decrypts it.
Step 2: Identify private key function
The private key is kept secret and used to decrypt messages encrypted by the public key.
Final Answer:
To decrypt messages encrypted with the public key -> Option C
Quick Check:
Private key = decrypt [OK]
Hint: Private key always decrypts what public key encrypts [OK]
Common Mistakes:
Confusing encryption and decryption roles
Thinking private key is shared publicly
Assuming private key encrypts messages
2. Which of the following is the correct way to describe RSA keys?
easy
A. Both keys are identical and interchangeable
B. Public key encrypts, private key decrypts
C. Private key is public, public key is private
D. Keys are randomly generated but not related
Solution
Step 1: Recall RSA key relationship
RSA uses a pair of keys where the public key encrypts and the private key decrypts.
Step 2: Evaluate options
Only Public key encrypts, private key decrypts correctly states the roles of the keys in RSA encryption.
Final Answer:
Public key encrypts, private key decrypts -> Option B
Quick Check:
Public encrypt, private decrypt [OK]
Hint: Public encrypts, private decrypts in RSA [OK]
Common Mistakes:
Thinking keys are the same
Mixing up public and private key roles
Believing keys are unrelated
3. Consider this simplified RSA scenario: Public key: (e=3, n=33) Private key: (d=7, n=33) Message m = 4 What is the encrypted message c using c = m^e mod n?
medium
A. 31
B. 12
C. 16
D. 4
Solution
Step 1: Calculate encryption formula
Compute c = 4^3 mod 33 = 64 mod 33.
Step 2: Find remainder
64 divided by 33 leaves remainder 64 - 33*1 = 31, so 64 mod 33 = 31.
Step 3: Re-check calculation
Actually, 4^3 = 64, 64 mod 33 = 31, so c = 31.
Final Answer:
31 -> Option A
Quick Check:
4^3 mod 33 = 31 [OK]
Hint: Calculate power then mod for encryption [OK]
Common Mistakes:
Forgetting to apply modulo
Calculating power incorrectly
Mixing up encryption and decryption formulas
4. In an RSA implementation, a developer wrote: c = (m ** d) % n to encrypt a message. Why is this incorrect?
medium
A. Because d is the private key exponent used for decryption, not encryption
B. Because m should be raised to e for decryption
C. Because modulo n should not be used in RSA
D. Because exponentiation operator ** is invalid in Python
Solution
Step 1: Understand RSA key usage
Encryption uses the public exponent e, decryption uses private exponent d.
Step 2: Identify error in code
The code uses d to encrypt, which is incorrect; it should use e.
Final Answer:
Because d is the private key exponent used for decryption, not encryption -> Option A
Quick Check:
Encrypt with e, decrypt with d [OK]
Hint: Encrypt with e, decrypt with d [OK]
Common Mistakes:
Using private key exponent for encryption
Confusing exponentiation operator validity
Ignoring modulo operation necessity
5. A company wants to use RSA to securely send a 128-bit message. Which of the following is the best practice to ensure security and efficiency?
hard
A. Encrypt the entire 128-bit message directly with RSA public key
B. Share the private key with the recipient to speed up encryption
C. Use the private key to encrypt the message and public key to decrypt
D. Use RSA to encrypt a symmetric key, then use that key to encrypt the message
Solution
Step 1: Understand RSA limitations
RSA is slow and inefficient for large data encryption like 128-bit messages directly.
Step 2: Identify best practice
Common practice is to encrypt a symmetric key with RSA, then use that key for fast message encryption.
Final Answer:
Use RSA to encrypt a symmetric key, then use that key to encrypt the message -> Option D
Quick Check:
Hybrid encryption = RSA + symmetric key [OK]
Hint: Encrypt keys with RSA, data with symmetric cipher [OK]
Common Mistakes:
Encrypting large data directly with RSA
Sharing private key publicly
Reversing encryption/decryption key roles
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.