Man-in-the-middle attacks in Cybersecurity - Time & Space Complexity
When studying man-in-the-middle attacks, it helps to understand how the attack effort grows as the amount of data or number of connections increases.
We want to know how the attacker's work changes when more messages or users are involved.
Analyze the time complexity of the following simplified attack process.
for message in network_traffic:
intercept(message)
decrypt(message)
modify(message)
forward(message)
log_attack_details()
This code shows an attacker intercepting and altering each message passing between two parties.
Look at what repeats as the input grows.
- Primary operation: Looping through each message in the network traffic.
- How many times: Once for every message sent between users.
As the number of messages increases, the attacker must process each one individually.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 message interceptions |
| 100 | 100 message interceptions |
| 1000 | 1000 message interceptions |
Pattern observation: The work grows directly with the number of messages; double the messages, double the work.
Time Complexity: O(n)
This means the attacker's effort increases in a straight line as more messages are intercepted.
[X] Wrong: "Intercepting one message means the attacker can handle all messages instantly without extra work."
[OK] Correct: Each message requires separate interception and processing, so effort grows with message count.
Understanding how attack effort scales helps you think like both attackers and defenders, a valuable skill in cybersecurity roles.
"What if the attacker could batch process multiple messages at once? How would the time complexity change?"