Timing Attack Visualizer

See exactly why a naive string comparison leaks how many leading characters were correct — and why constant-time comparison fixes it.

A timing attack extracts secrets from how long a computation takes rather than what it returns. The classic case is string comparison that stops at the first wrong character — it leaks, one character at a time, how much of your guess was right. This page shows that leak happening.

How to use it

  1. Watch the secret being guessed against your guess.
  2. Compare the naive comparison against the constant-time comparison.
  3. Observe how the matched prefix grows under the naive version and does not under the other.

What to take away

Early exit is the whole bug

A comparison that returns as soon as it finds a mismatch takes longer for a more correct guess. That turns an exponential search into a linear one — character by character rather than all at once.

Constant-time means always the same work

A safe comparison examines every byte regardless, accumulating differences and checking once at the end. Use your language's provided function — hmac.compare_digest, crypto.timingSafeEqual — rather than writing one.

Network noise raises the cost, not the impossibility

Real timing attacks average many requests to pull the signal out of jitter. Remote timing attacks against real services have been demonstrated repeatedly; "it is over the network" is not a defence.

Frequently asked questions

What is a side-channel attack?

One that reads something other than the intended output — time taken, power drawn, cache state, sound. The algorithm can be perfect and still leak through how it runs.

Where does this matter in practice?

Anywhere a secret is compared: API keys, HMAC signatures, password reset tokens, session identifiers. Signature verification is the most commonly affected.

How do I fix it in my own code?

Never compare secrets with == or a loop that breaks early. Use the constant-time comparison your standard library already provides.

Where this fits in the course

This security tool pairs with Path 06 — Cryptography — see all 26 learning paths.

It runs entirely in your browser: nothing is uploaded, no account is needed, and it is free.

Related

  • Diffie-Hellman Key Exchange Visualizer — Watch two sides land on the same shared secret without ever transmitting it, with small real numbers.
  • Webhook Signature Forgery Lab — Forge an HMAC-signed webhook without the secret, then flip on signature verification and watch it get rejected.
  • Race Condition Lab — A one-time coupon, redeemed with a check-then-act flaw. Fire requests fast enough and redeem it far more than once.
  • Entropy Calculator — Shannon entropy of any text — a genuine static-analysis signal for spotting packed or encrypted data.

Browse all 32 security tools →