0
0
Cybersecurityknowledge~5 mins

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

Choose your learning style9 modes available
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?"