zoukankan      html  css  js  c++  java
  • 生成otp token 脚本

    #!/usr/bin/python3
     
    import re
    import time
    import hashlib
    import struct
    import base64
    import hmac
    from random import choice
    from string import ascii_letters, digits
    from sys import argv
    secret = '这里是你的secret'
    mangling_string = 'ASGIw3gQMAbEw6z4u8xxmfwYx5qG4b16'
    def get_hotp_token(secret, intervals_no):
    key = base64.b32decode(secret, True)
    msg = struct.pack(">Q", intervals_no)
    h = hmac.new(key, msg, hashlib.sha1).digest()
    o = h[19] & 15
    h = (struct.unpack(">I", h[o:o+4])[0] & 0x7fffffff) % 1000000
    return h



    def get_totp_token(secret):
    return get_hotp_token(secret, intervals_no=int(time.time())//30)



    def xor_crypt_string(data, key='awesomepassword', encode=False, decode=False):
    from sys import byteorder
    import base64
    if decode:
    data = base64.decodebytes(bytearray(data, 'ascii'))
    else:
    data = bytearray(data, 'ascii')
    while (len(data) > len(key)):
    key += key
    key = key[:len(data)]
    key = bytearray(key, 'ascii')
    int_data = int.from_bytes(data, byteorder)
    int_key = int.from_bytes(key, byteorder)
    int_enc = int_data ^ int_key
    int_enc = int_enc.to_bytes(len(data), byteorder)
    if encode:
    return base64.encodebytes(int_enc).strip()
    return int_enc



    # extract params:
    if (len(argv) > 1):
    secret = argv[1]
    try:
    token = get_totp_token(xor_crypt_string(
    secret, mangling_string, decode=True))
    except:
    print("Invalid Secret")
    token = '123456' + '%06d' % token
    print(token)
     
     
     
    ## https://github.com/vitorgalvao/custom-alfred-iterm-scripts
  • 相关阅读:
    Ynoi 杂题选做
    CSP-S2021 浙江 游记
    P6272 [湖北省队互测2014]没有人的算术
    P5206 [WC2019]数树
    P5405 [CTS2019]氪金手游
    LOJ6679 Unknow
    LOJ3040 「JOISC 2019 Day4」合并
    P6122 [NEERC2016]Mole Tunnels
    三维凸包
    三,四元环计数
  • 原文地址:https://www.cnblogs.com/sweetsunnyflower/p/14339847.html
Copyright © 2011-2022 走看看