This is a code generator for the Time-based One Time Password (TOTP) algorithm.


What is this?

This is a code generator for the Time-based One Time Password (TOTP) algorithm. It's intended for developers of web applications with TOTP support to quickly generate codes for testing purposes. It's not meant to be a general purpose authenticator app.

What this tool can do:

  • Quickly generate TOTP codes;
  • View codes for past and future time windows; and
  • Fiddle with various TOTP parameters.

What this tool can't do:

  • Store your TOTP secrets (you can try bookmarking this page with the secret in the URL, but it's not secure);
  • Act as your general purpose authenticator app; and
  • Scan TOTP QR codes.

How do I use this tool?

To start, simply type or paste in the TOTP secret key. This should be in the standard base32 format. This will generate 6-digit TOTP codes that update every 30 seconds using the SHA-1 algorithm that's used by default in all major authenticator apps.

You can press "show advanced settings" to adjust the TOTP parameters to use non-default values.

The generated codes are displayed in chronological order. The current code is shown in large text. The codes above are past codes, and the codes below are future codes.

The settings are stored in the URL hash. You can bookmark the page or copy the link to go directly to a certain configuration.

How does TOTP work?

Time-based one-time password (TOTP), defined in RFC 6238, is based on the HMAC-based one-time password (HOTP) algorithm, which uses the common HMAC construction based on the current time. TOTP requires the following inputs:

  • The cryptographic hash function H, which defaults to SHA-1. This is configurable in the advanced settings;
  • The secret key K, which is commonly encoded as Base32. This value, encoded in Base32, is what you enter into the secret key field;
  • The time window X, which is how long each code is valid for;
  • The epoch T0, which is the Unix epoch (0 in Unix time) in every known implementation, but could be changed; and
  • The number of digits d, which is the length of the final output code in decimal digits.

The algorithm is as follows:

  1. Take the current unix time U;
  2. Compute the time step count T=\left\lfloor\frac{U - T_0}{X}\right\rfloor;
  3. Compute the HMAC h = \text{HMAC}_H(K, T);
  4. Extract the 4 lowest order bits, i.e. the 4 least significant bits from the last byte of h, to create the integer i;
  5. Take four bytes from h starting at i, i.e. bytes [i, i+4), mask off the most significant bit (to support signed arithmetic), and use it to create the integer y; and finally
  6. Compute the code as y \bmod{10^d}, zero-padded to d digits.

Express as Python code, the last 3 steps would look like:

i = h[-1] & 0xF
y = (
    (h[i + 0] & 0x7F) << 24 |
    (h[i + 1] & 0xFF) << 16 |
    (h[i + 2] & 0xFF) << 8 |
    (h[i + 3] & 0xFF)
)
code = str(y % 10**d).rjust(d, '0')

To avoid clock synchronization issues, most implementations will accept TOTP codes from the window before and after the one based on the current time. This tool lets you see the previous and next codes to help you debug.

I like this website. How can I support you?

For security reasons, this website will NEVER serve ads. Unfortunately, servers and domains are not free, though I try to be as economical as I can. I would rather lose money running this public service than serve ads or shut it down, but if you would like to help me offset the costs, feel free to send some money my way on: