Security and privacyExhibit 15

How do 2FA codes work without internet?

Your authenticator app and the website share one secret, set up once with a QR code. Every 30 seconds, each side mixes that secret with the current time and gets the same six digits on its own. Nothing is sent when the code is made, which is why it works in airplane mode.

Try it: watch a code being made

This is a working code generator, the same method authenticator apps use. Everything is calculated in your browser; nothing is sent anywhere. Use the demo secret or make a new one. Do not paste a real account secret into any web page.

Secret (shared once, in the QR code)
Seconds since 1970, divided by 30

Secret and counter go into HMAC, a one-way function. Out come 20 bytes. The last byte says where to cut 4 bytes (yellow):

Those 4 bytes as a number, keeping the last six digits:

··· ···

This follows the public standards RFC 4226 and RFC 6238 with the usual settings: SHA-1, 30-second steps, six digits. The line at the bottom runs the official test from the standard every time the page loads.

The video for this exhibit comes out on YouTube on Friday 18 December. Subscribe so you don’t miss it

One secret, shared once

When you turn on two-factor login, the website shows a QR code. Inside it is a secret key: a long random string. Your phone saves it, and the website keeps the same one. That scan is the only time the secret has to travel. Logging in never sends it again.

The clock does the rest

Both sides already have the second ingredient: the time. Computers count time as seconds since the start of 1970. The standard for these codes, published in 2011, says: divide that number by 30 and drop the remainder. The result is a counter that goes up by one every 30 seconds, the same on every device with the right time.

Mix, cut, keep six digits

The phone feeds the secret and the counter into a one-way function called HMAC. Out come 20 bytes that look random. The standard picks 4 of them, reads them as one big number and keeps the last six digits. The server does the same math with its copy of the secret and checks that the digits match. Because the function runs only one way, seeing a code does not reveal the secret.

The weak spot

A code proves you hold the secret. It does not check which website you are typing it into. A fake login page can ask for your code and pass it to the real site while it is still valid. Codes stop someone who only stole your password; they do not stop a fake page that relays everything live. Passkeys and security keys are built to close that gap.

Frequently asked questions

Why do authenticator apps work without internet?

The code is calculated on your phone from a stored secret and the current time. No message is exchanged with the website when the code is made, so no connection is needed.

What happens if my phone's clock is wrong?

If the clock is off by more than a step or so, the codes will not match. Servers usually also accept the code from the previous 30 seconds to allow for small differences and typing time.

Can someone guess a six-digit code?

There are a million possible codes, so one guess has about a one-in-a-million chance for each code the server accepts. That is why servers limit the number of tries, and why each code works only once.

Sources

Last updated

Keep exploring