0
0
Computer Networksknowledge~5 mins

Symmetric encryption (AES, DES) in Computer Networks - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Symmetric encryption (AES, DES)
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As the data size grows, the number of blocks to encrypt grows proportionally.

Input Size (n bytes)Approx. Number of Blocks
10About 1 block
100About 7 blocks (if block size is 16 bytes)
1000About 63 blocks

Pattern observation: Doubling the data roughly doubles the number of blocks and 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 data.

Common Mistake

[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.

Interview Connect

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.

Self-Check

What if the encryption algorithm processed data in variable-sized blocks instead of fixed blocks? How would the time complexity change?