Asymmetric encryption (RSA, ECC) in Cybersecurity - Time & Space 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.
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.
- 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).
As the message size (exponent) grows, the number of multiplications grows roughly the same amount.
| Input Size (message) | Approx. Operations |
|---|---|
| 10 | 10 multiplications |
| 100 | 100 multiplications |
| 1000 | 1000 multiplications |
Pattern observation: Doubling the message size roughly doubles the work needed.
Time Complexity: O(n)
This means the time to encrypt grows directly in proportion to the size of the message or exponent.
[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.
Understanding how encryption time grows helps you explain performance trade-offs in security systems clearly and confidently.
"What if we use a faster method like exponentiation by squaring instead of simple repeated multiplication? How would the time complexity change?"