News for hackers. Stuff that matters.
Re:Tiny Toy TOTP Generator in 18 Lines of Python by userbinator on Sunday August 11, 2019 @02:46PM (#20669703)
I'd say these are the 4 most important, because they show the actual core of the algorithm; everything else is just input/output:

    mac = hmac.new(secret_bytes, counter_bytes, digest).digest()
    offset = mac[-1] & 0x0f
    truncated = struct.unpack('>L', mac[offset:offset+4])[0] & 0x7fffffff
    return str(truncated)[-digits:].rjust(digits, '0')
In other words, HMAC your secret key with the time and pick digits using the output of the HMAC.

There are no comments on this comment yet.