将这段代码转为python const timestamp = Date.now(); const userid = 0; const securityKey = Math.floor(1e8 * Math.random()); const i = `${timestamp}:${userid}:${securityKey}`; let list = []; const e = encodeURI(i); for(let i=0; i<e.length; i++) { list.push(e.charCodeAt(i)); } list = new Uint8Array(list); const a = [68, 107, 79, 108, 105, 87, 118, 70, 78, 82, 55, 67, 52, 87, 118, 82]; // const a = [51, 80, 77, 71, 82, 81, 79, 50, 57, 69, 51, 54, 73, 68, 72, 56]; const b = new Uint8Array([71, 81, 87, 75, 85, 69, 50, 67, 86, 71, 79, 79, 66, 75, 88, 85]); const key = new Uint8Array(a); const aesCfb = new aesjs.ModeOfOperation.cfb(key, b); const encryptedBytes = aesCfb.encrypt(list); const token = aesjs.utils.hex.fromBytes(encryptedBytes); return { timestamp, userid, securityKey, token };
时间: 2023-11-17 19:06:03 浏览: 84
```python
import time
import random
import aes
import binascii
timestamp = int(time.time() * 1000)
userid = 0
securityKey = random.randint(0, 99999999)
i = f"{timestamp}:{userid}:{securityKey}"
list = []
e = i.encode('utf-8').decode('unicode-escape')
for char in e:
list.append(ord(char))
list = bytes(list)
a = [68, 107, 79, 108, 105, 87, 118, 70, 78, 82, 55, 67, 52, 87, 118, 82]
b = bytes([71, 81, 87, 75, 85, 69, 50, 67, 86, 71, 79, 79, 66, 75, 88, 85])
key = bytes(a)
aesCfb = aes.ModeOfOperationCFB(key, b)
encryptedBytes = aesCfb.encrypt(list)
token = binascii.hexlify(encryptedBytes).decode()
return {
'timestamp': timestamp,
'userid': userid,
'securityKey': securityKey,
'token': token
}
```
阅读全文