-
-
Save toshsan/7faf3f67e6768196b7ad to your computer and use it in GitHub Desktop.
TOPT Code generator, for use with 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 time | |
import hmac | |
import struct | |
import base64 | |
import hashlib | |
def code(secret): | |
key = base64.b32decode(secret) | |
message = struct.pack(">Q", int(time.time()) / 30) | |
h = hmac.new(key, message, hashlib.sha1).digest() | |
offset = ord(h[19]) & 0xF | |
code = (struct.unpack(">I", h[offset:offset+4])[0] & 0x7FFFFFFF) % 1E6 | |
print "{0:06n}".format(code) | |
code("AAAAAAAAAAAAAAAA") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment