HOTP (HMAC-based One-Time Password) sinh OTP từ khóa bí mật và một bộ đếm:
hs = HMAC-SHA1(key, counter_8byte_big_endian)offset = hs[19] & 0x0fbin = (hs[offset]&0x7f)<<24 | hs[offset+1]<<16 | hs[offset+2]<<8 | hs[offset+3]HOTP = bin mod 10^digits, đệm 0 bên trái cho đủ digits chữ số.key là chuỗi ASCII (dùng trực tiếp làm byte). Counter lấy từ đầu vào (không dùng thời gian).
Ví dụ: key=12345678901234567890, counter=0, digits=6 → 755224 (vector chuẩn RFC 4226).
Dòng 1: secret (ASCII). Dòng 2: counter. Dòng 3 (tùy chọn): số chữ số digits (mặc định 6).
0 ≤ counter ≤ 2^63−1. 6 ≤ digits ≤ 8.
1 dòng: mã HOTP đã đệm 0.
Ví dụ:
Đầu vào:
12345678901234567890
0
6
Đầu ra:
755224
Giải thích:
Đang tải editor...