尝试像这样对每26个字符长度块进行加密,首先将其转换为一个字节数组,然后使用regex查找字节数组中的每个\x,然后使用AES对其进行加密。
import re
import base64
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
key=get_random_bytes(16)
generator = AES.new(key, AES.MODE_CCM)
crypt=""
textHex="87315a69020000006400110400096d617274696e657433010882848b962430486c03010b0504000100002a01042f010432040c121860dd06001018010100dd160050f20101000050f20201000050f20201000050f202"
textBlocks=re.findall('.{1,26}',textHex)
for i in range(0,len(textBlocks)):
textBlocks[i]=bytes.fromhex(textBlocks[i])
textBlocks2=re.findall('.+?(?=\\\x)', textBlocks[i])
for j in range(0,len(textBlocks2):
crypt += generator.encrypt(textBlocks2[j])问题是正则表达式不能识别\x00

同样,当此正则表达式在RegExr上工作时,python将显示以下错误
SyntaxError:(unicode错误)‘独角形转义’编解码器无法解码位置8-9的字节:截断\xXX转义
发布于 2018-03-09 04:52:57
如果问题只是得到最后一个\x00
您可以对javascript使用以下regex:.+?(?=\\\x|$)
演示:https://regex101.com/r/4ieyDq/1
如果您想要的是一个python regex,那么可以使用:.+?(?=\\x|$)
https://stackoverflow.com/questions/49186639
复制相似问题