b2KIT

HOTP Code Generator

Generate HMAC-based One-Time Password codes from a secret key and counter value for two-factor authentication.

Tested tool guide Tested browser tools Checked August 16, 2026

What HOTP Code Generator does, with a checked example

HOTP Code Generator turns a shared secret and an explicit counter into the decimal passcode defined by HOTP. It applies HMAC-SHA-1 to an eight-byte counter, dynamically truncates the result, and formats the requested number of digits. The counter is event based, not a timestamp: a correct secret still produces the wrong code when the generator and verifier use different counter values. Because the secret is an authentication credential, enter it only on a trusted device. The calculation runs in the browser, and the secret is not uploaded.

Worked example

A concrete input and expected output from the current implementation.

Input

Secret (Base32): GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ
Counter: 0
Digits: 6

Expected output

755224

The Base32 text decodes to the 20 ASCII bytes 12345678901234567890, the shared secret used in the RFC 4226 test vectors. Dynamic truncation produces 1,284,755,224 for counter 0, and reducing that value modulo 1,000,000 gives 755224.

How the result is produced

1

Counter encoding

RFC 4226 represents the counter as an unsigned 64-bit value in network byte order. HOTP computes HMAC-SHA-1 using the secret key bytes as the HMAC key and those eight counter bytes as the message. Counter 1 therefore means the eight-byte value 0000000000000001, not the text character "1".

2

Dynamic truncation

The low four bits of the final HMAC byte select an offset. Four bytes beginning at that offset are converted into a nonnegative 31-bit integer. Taking that integer modulo 10^d yields a d-digit HOTP code, with leading zeroes added when necessary. For the six-digit setting used in the example, the modulus is 1,000,000.

Good uses

  • Reproduce an RFC 4226 test vector while checking an HOTP implementation or authentication integration.
  • Compare a token's expected code with a backend calculation during counter synchronization troubleshooting.
  • Generate an event-based two-factor authentication code when the provisioned secret and exact counter are known.

Limits and checks

  • Confirm the secret's encoding. The example secret is Base32 text representing key bytes; using those visible Base32 characters as literal key bytes produces a different code.
  • Confirm the counter exactly. Adjacent counter values produce unrelated-looking codes, and this result cannot reveal which counter the verifier currently expects.
  • Treat the result as a fixed-width decimal string. Leading zeroes are significant, and using a different digit length changes the displayed code.

Common questions

Is HOTP the same as TOTP?

No. HOTP uses an explicit moving counter that advances with token events. TOTP derives its moving factor from fixed time steps, so clock agreement matters there instead of agreement on a stored event counter. Although TOTP applies the HOTP calculation to its time-derived value, HOTP and TOTP credentials are not interchangeable during ordinary enrollment.

Can I use the same counter twice?

The calculation is deterministic, so the same secret, counter, and digit length produce the same code every time. That does not guarantee the code can authenticate twice. A verifier commonly records counter progress and rejects a code associated with an already accepted counter. Follow the counter advancement and resynchronization rules of the system receiving the code.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools