HOTP & TOTP Calculator

Generate and verify HMAC-based (HOTP) and Time-based (TOTP) one-time passwords. Supports SHA-1, SHA-256, SHA-512, 6–8 digit codes. All computation runs in your browser — your secret is never sent anywhere.

Input Parameters
Result
------
Click Generate to compute
Time remaining: --s

How HOTP & TOTP Work

Core algorithm: Both HOTP and TOTP compute HMAC-SHA1(K, C) where K is the shared secret and C is the counter (HOTP) or time-derived counter (TOTP). The HMAC output is then dynamically truncated to produce a 6–8 digit code.

HOTP (RFC 4226) — Counter-Based

HOTP uses an incrementing counter shared between the client and server. Each generation increments the counter by 1:

HOTP(K, C) = Truncate(HMAC-SHA1(K, C)) mod 10^d
// C = counter (8-byte big-endian)
// d = digit count (6, 7, or 8)

Use case: Event-based OTP tokens, OATH HOTP tokens, smart card challenge-response (some PIV cards).

TOTP (RFC 6238) — Time-Based

TOTP replaces the counter with a time-derived value:

T = floor((CurrentTime - T0) / X)
TOTP(K, T) = Truncate(HMAC-SHA1(K, T)) mod 10^d
// T0 = epoch start (usually 0)
// X = time step (typically 30 or 60 seconds)

Use case: Google Authenticator, Authy, Microsoft Authenticator, 2FA apps, FIDO2/U2F time-based challenges.

Dynamic Truncation

The HMAC output (20 bytes for SHA-1, 32 for SHA-256, 64 for SHA-512) is truncated to produce a numeric code:

1. offset = hmac[hamc_length-1] & 0x0F
2. code = ((hmac[offset]   & 0x7F) << 24) |
          ((hmac[offset+1] & 0xFF) << 16) |
          ((hmac[offset+2] & 0xFF) << 8)  |
           (hmac[offset+3] & 0xFF)
3. otp = code % 10^d   (d = digit count)

Smart Card & Security Key Applications

ApplicationOTP TypeAlgorithmDetails
PIV Card (NIST SP 800-73)HOTPSHA-1 / SHA-256Card internal counter, challenge-response mode
OATH Token (YubiKey)HOTP + TOTPSHA-1 / SHA-256YubiKey stores multiple OATH credentials
Google AuthenticatorTOTPSHA-130s step, 6 digits, Base32 secret
RFC 6238 Test VectorsTOTPSHA-1/256/5128 digits, 30s step, test times from RFC
EMV CAP (Chip Authentication)HOTP-likeSHA-1Banking card generates transaction codes

RFC 6238 Test Vectors

You can verify your implementation against these known test vectors (secret = 12345678901234567890 in ASCII, 8-digit TOTP):

Time (Unix)TSHA-1SHA-256SHA-512
591942870824611924690693936
111111110937037036070818046806477425091201
123456789041152263890125946806477425091201
200000000066666666692790379181942477737706

Code Example (Python)

import hmac, hashlib, struct, time

def hotp(secret: bytes, counter: int, digits: int = 6, algo: str = 'sha1') -> str:
    msg = struct.pack('>Q', counter)
    h = hmac.new(secret, msg, algo).digest()
    offset = h[-1] & 0x0F
    code = ((h[offset] & 0x7F) << 24 |
            (h[offset+1] & 0xFF) << 16 |
            (h[offset+2] & 0xFF) << 8 |
            (h[offset+3] & 0xFF))
    return str(code % 10**digits).zfill(digits)

def totp(secret: bytes, digits: int = 6, period: int = 30, algo: str = 'sha1') -> str:
    t = int(time.time()) // period
    return hotp(secret, t, digits, algo)

# Usage
secret = b'12345678901234567890'
print(f"HOTP(counter=0): {hotp(secret, 0)}")  # 755224
print(f"TOTP(now):       {totp(secret)}")
Security note: This tool runs entirely in your browser. Your secret key is never transmitted. However, do not use this tool with production 2FA secrets on shared or untrusted devices.