Last active
August 29, 2015 14:07
-
-
Save djui/6f64dab33c25944fa0da to your computer and use it in GitHub Desktop.
Shortest TOTP I know of
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import base64,hashlib,hmac,struct,time,sys | |
if not len(sys.argv[1:]): sys.exit('usage: totp <secret>') | |
digest = hmac.new(base64.b32decode(sys.argv[1]), struct.pack('>Q', int(time.time()) // 30), hashlib.sha1).digest() | |
offset = ord(digest[19]) & 15 | |
print '06d' % (struct.unpack('>I', digest[offset:offset+4])[0] & 0x7fffffff % 1000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment