Created
September 12, 2017 17:51
-
-
Save aniline/d5e11d8d20cd96f2f5d7ae731566be94 to your computer and use it in GitHub Desktop.
TOTP like Google Authenticator
This file contains 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
import hashlib, hmac, base64, struct, time, math | |
def GoogleTOTP(s): | |
msg = int(math.floor(time.time()/30)) | |
hm = hmac.new(base64.b32decode(s), struct.pack('>q', msg), hashlib.sha1).digest() | |
offs = ord(hm[-1]) & 0xF | |
code = str(((struct.unpack('>L',hm[offs:offs+4])[0]) & 0x7FFFFFFF) % 1000000).zfill(6) | |
return code | |
print GoogleTOTP("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment