RFC 6238 TOTP generation

Write codeMedium30 minCoinbase style

Your task

Implement RFC 6238 TOTP. Given a base32-encoded shared secret, a Unix timestamp (seconds), a time step in seconds (e.g. 30), and the number of output digits, return the TOTP code as a zero-padded string. Compute the counter as floor(timestamp / step), pack it as an 8-byte big-endian value, HMAC-SHA1 it with the decoded secret, apply the standard dynamic truncation (offset = last nibble of the digest; take 4 bytes starting there, mask the top bit), then take modulo 10**digits and left-pad with zeros to 'digits' length.

Examples

totp(secret_b32: str, timestamp: int, step: int, digits: int) -> str
Example 1
Inputtotp("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ", 59, 30, 6)
Output"287082"