LEN

Python 谷歌令牌计算
#!/usr/local/bin/python # coding: utf8 ''' Google Auth A...
扫描右侧二维码阅读全文
13
2019/03

Python 谷歌令牌计算

#!/usr/local/bin/python
# coding: utf8

'''
Google Auth Algorithm Caculator
'''

import hmac, base64, struct, hashlib, time, sys

def calGoogleCode(secretKey):
    input = int(time.time())//30
    key = base64.b32decode(secretKey)
    msg = struct.pack(">Q", input)
    googleCode = hmac.new(key, msg, hashlib.sha1).digest()
    o = ord(googleCode[19]) & 15
    googleCode = str((struct.unpack(">I", googleCode[o:o+4])[0] & 0x7fffffff) % 1000000)
    if len(googleCode) == 5:
        googleCode = '0' + googleCode
    return googleCode


print '账号 123 123@163.com ' + calGoogleCode('MUVL174MJQOUU45U')
 
最后修改:2019 年 03 月 13 日 07 : 09 PM
如果觉得我的文章对你有用,请随意赞赏

发表评论