[From github-ykdl] Youku Utid

2019-1-26 admin 算法

import time
import struct
import hmac
import base64
import random
import hashlib
from ctypes import c_int

def hashCode(str):
    res = c_int(0)
    if not isinstance(str, bytes):
        str = str.encode()
    for i in bytearray(str):
        res = c_int(c_int(res.value * 0x1f).value + i)
    return res.value

def generateUtdid():
    timestamp = int(time.time()) - 60 * 60 * 8
    i31 = random.randrange(1 << 31)
    imei = hashCode(str(i31))
    msg = struct.pack('!2i2bi', timestamp, i31, 3, 0, imei)
    key = b'd6fc3a4a06adbde89223bvefedc24fecde188aaa9161'
    data = hmac.new(key, msg, hashlib.sha1).digest()
    msg += struct.pack('!i', hashCode(base64.standard_b64encode(data)))
    return base64.standard_b64encode(msg)

标签: youku utid

评论:

麻辣
2019-04-13 14:29
如此好文章一定要留下名啊
西安seo
2019-01-28 09:49
表示没看懂啊,大佬级别,路过了

发表评论:

Powered by emlog