Bird
Raised Fist0
Cybersecurityknowledge~5 mins

Asymmetric encryption (RSA, ECC) in Cybersecurity - Time & Space Complexity

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Time Complexity: Asymmetric encryption (RSA, ECC)
O(n)
Understanding Time Complexity

When using asymmetric encryption like RSA or ECC, it is important to understand how the time to encrypt or decrypt changes as the size of the input or key grows.

We want to know how the work needed grows when we use bigger keys or encrypt larger messages.

Scenario Under Consideration

Analyze the time complexity of the following simplified RSA encryption process.


// Simplified RSA encryption
function rsaEncrypt(message, publicKey, n) {
  let encrypted = 1n;
  for (let i = 0n; i < message; i++) {
    encrypted = (encrypted * publicKey) % n;
  }
  return encrypted;
}

This code raises the public key to the power of the message modulo n, simulating RSA encryption.

Identify Repeating Operations
  • Primary operation: Multiplying and taking modulo repeatedly inside the loop.
  • How many times: The loop runs once for each unit of the message size (the exponent).
How Execution Grows With Input

As the message size (exponent) grows, the number of multiplications grows roughly the same amount.

Input Size (message)Approx. Operations
1010 multiplications
100100 multiplications
10001000 multiplications

Pattern observation: Doubling the message size roughly doubles the work needed.

Final Time Complexity

Time Complexity: O(n)

This means the time to encrypt grows directly in proportion to the size of the message or exponent.

Common Mistake

[X] Wrong: "Encryption time stays the same no matter how big the message or key is."

[OK] Correct: Larger messages or keys require more calculations, so the time grows with their size.

Interview Connect

Understanding how encryption time grows helps you explain performance trade-offs in security systems clearly and confidently.

Self-Check

"What if we use a faster method like exponentiation by squaring instead of simple repeated multiplication? How would the time complexity change?"

Practice

(1/5)
1. What is the main purpose of asymmetric encryption like RSA and ECC?
easy
A. To use the same key for both encrypting and decrypting
B. To store passwords in plain text
C. To use two different keys: one to encrypt and one to decrypt
D. To speed up internet connections

Solution

  1. Step 1: Understand key usage in asymmetric encryption

    Asymmetric encryption uses two keys: a public key to encrypt and a private key to decrypt messages.
  2. Step 2: Compare with symmetric encryption

    Symmetric encryption uses the same key for both encrypting and decrypting, which is different from asymmetric encryption.
  3. Final Answer:

    To use two different keys: one to encrypt and one to decrypt -> Option C
  4. Quick Check:

    Asymmetric encryption = two keys (public/private) [OK]
Hint: Remember: public key encrypts, private key decrypts [OK]
Common Mistakes:
  • Confusing asymmetric with symmetric encryption
  • Thinking one key is used for both encrypting and decrypting
  • Believing encryption speeds up internet
  • Assuming passwords are stored in plain text
2. Which of the following is a correct statement about RSA keys?
easy
A. RSA does not use any mathematical operations
B. RSA uses a single key for both encryption and decryption
C. RSA keys are always 128 bits long
D. RSA keys are generated using large prime numbers

Solution

  1. Step 1: Recall RSA key generation method

    RSA keys are created by multiplying two large prime numbers to form the public and private keys.
  2. Step 2: Check other options for correctness

    RSA does not use a single key, keys are not fixed at 128 bits, and it heavily relies on math operations.
  3. Final Answer:

    RSA keys are generated using large prime numbers -> Option D
  4. Quick Check:

    RSA key generation = large primes [OK]
Hint: RSA keys come from multiplying big prime numbers [OK]
Common Mistakes:
  • Thinking RSA uses one key only
  • Assuming RSA keys have fixed small size
  • Ignoring the role of prime numbers
  • Believing RSA avoids math operations
3. Consider this simplified RSA encryption example:
public_key = (e=3, n=33)
private_key = (d=7, n=33)
message = 4
encrypted = (message^e) mod n
decrypted = (encrypted^d) mod n

What is the decrypted message?
medium
A. 4
B. 7
C. 3
D. 9

Solution

  1. Step 1: Calculate encrypted message

    encrypted = (4^3) mod 33 = 64 mod 33 = 31
  2. Step 2: Calculate decrypted message

    decrypted = (31^7) mod 33. Calculating 31^7 mod 33 gives 4 (using modular exponentiation).
  3. Final Answer:

    4 -> Option A
  4. Quick Check:

    Decrypted message matches original message [OK]
Hint: Encrypt then decrypt returns original message [OK]
Common Mistakes:
  • Forgetting to apply modulo operation
  • Mixing up public and private keys
  • Incorrectly calculating powers
  • Assuming encrypted equals decrypted
4. A developer wrote this ECC key generation snippet but it fails:
private_key = generate_ecc_key()
public_key = private_key * G

What is the likely error?
medium
A. Public key is generated by multiplying G by private key, not the other way
B. Private key must be a point, not a number
C. Private key cannot be used to generate public key
D. Multiplying private key by G is incorrect; should add G

Solution

  1. Step 1: Understand ECC key generation

    In ECC, the public key is generated by multiplying the base point G by the private key scalar.
  2. Step 2: Identify the error in code

    The code multiplies private_key by G, but the correct order is G multiplied by private_key.
  3. Final Answer:

    Public key is generated by multiplying G by private key, not the other way -> Option A
  4. Quick Check:

    ECC public key = G * private key [OK]
Hint: Order matters: base point times private key [OK]
Common Mistakes:
  • Reversing multiplication order
  • Confusing addition with multiplication
  • Thinking private key is a point
  • Believing private key can't generate public key
5. Why might ECC be preferred over RSA for securing mobile devices?
hard
A. RSA is faster and more efficient on mobile devices
B. ECC uses smaller keys for similar security, saving battery and space
C. ECC keys are easier to guess than RSA keys
D. ECC does not require a private key

Solution

  1. Step 1: Compare key sizes and efficiency

    ECC achieves strong security with smaller keys compared to RSA, which helps reduce processing power and battery use on mobiles.
  2. Step 2: Evaluate other options

    ECC keys are not easier to guess; RSA is generally slower on mobiles; ECC requires private keys like RSA.
  3. Final Answer:

    ECC uses smaller keys for similar security, saving battery and space -> Option B
  4. Quick Check:

    ECC = smaller keys, better for mobiles [OK]
Hint: Smaller keys mean less power use on mobiles [OK]
Common Mistakes:
  • Thinking ECC keys are weaker
  • Assuming RSA is faster on mobiles
  • Believing ECC doesn't use private keys
  • Ignoring battery and space constraints