Symmetric encryption (AES, DES) in Computer Networks - Time & Space Complexity
When we use symmetric encryption like AES or DES, it is important to know how the time to encrypt or decrypt data changes as the data size grows.
We want to understand how the work needed grows when the message gets bigger.
Analyze the time complexity of the following simplified encryption process.
function symmetricEncrypt(data) {
for (let i = 0; i < data.length; i += blockSize) {
let block = data.slice(i, i + blockSize);
encryptBlock(block);
}
}
function encryptBlock(block) {
// Fixed steps to encrypt one block
}
This code splits data into blocks and encrypts each block one by one using a fixed process.
Look for repeated actions in the code.
- Primary operation: Encrypting each block of data.
- How many times: Once for every block, which depends on the total data size divided by block size.
As the data size grows, the number of blocks to encrypt grows proportionally.
| Input Size (n bytes) | Approx. Number of Blocks |
|---|---|
| 10 | About 1 block |
| 100 | About 7 blocks (if block size is 16 bytes) |
| 1000 | About 63 blocks |
Pattern observation: Doubling the data roughly doubles the number of blocks and the work needed.
Time Complexity: O(n)
This means the time to encrypt grows directly in proportion to the size of the data.
[X] Wrong: "Encrypting twice the data takes four times longer because encryption is very complex."
[OK] Correct: The encryption process works on fixed-size blocks, so doubling data doubles the blocks, doubling time, not quadrupling it.
Understanding how encryption time grows helps you explain performance in real systems where data size varies.
This skill shows you can think about how algorithms behave beyond just knowing how they work.
What if the encryption algorithm processed data in variable-sized blocks instead of fixed blocks? How would the time complexity change?