Why encryption protects data in Cybersecurity - Performance Analysis
We want to understand how the time needed to encrypt data changes as the amount of data grows.
How does the encryption process scale when protecting larger amounts of data?
Analyze the time complexity of the following encryption process.
function encryptData(data, key) {
let encrypted = "";
for (let i = 0; i < data.length; i++) {
encrypted += String.fromCharCode(data.charCodeAt(i) ^ key);
}
return encrypted;
}
This code encrypts data by processing each character with a simple operation using a key.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each character of the data string.
- How many times: Exactly once for every character in the data.
As the data gets longer, the time to encrypt grows in direct proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 operations (one per character) |
| 100 | 100 operations |
| 1000 | 1000 operations |
Pattern observation: Doubling the data size doubles the work needed.
Time Complexity: O(n)
This means the time to encrypt grows linearly with the amount of data.
[X] Wrong: "Encryption time stays the same no matter how much data there is."
[OK] Correct: Each piece of data must be processed, so more data means more work and more time.
Understanding how encryption time grows helps you explain efficiency and performance in real security tasks.
"What if the encryption used nested loops over the data? How would the time complexity change?"