我正在Python 3.7中工作,我想将编码后的字节转换为比特。
首先,我将 msg 和键(位转换为字节)转换。然后我用密钥加密味精。之后,我想将加密的味精转换为位。
text = "1100.." #256 bits
key = "0010..." #128 bits
msg = int(plain, 2).to_bytes((len(plain) + 7) // 8, 'big') #to bytes
key = int(key, 2).to_bytes((len(key) + 7) // 8, 'big') #to bytes
cipher = AES.new(key, AES.MODE_ECB)
encoded = cipher.encrypt(msg)