def encode_8(bytes, key, terminator):
"""
Encode the bytecode with the given 8-bit XOR key.
:type bytes: str
:param bytes: Bytecode to encode.
:type key: str
:param key: 8-bit XOR key.
:type terminator: str
:param terminator: 8-bit terminator.
:rtype: str
:return: Encoded bytecode.
"""
if not bytes.endswith(terminator):
bytes += terminator
fmt = "B" * len(bytes)
unpack = struct.unpack
pad = unpack("B", key) * len(bytes)
bytes = unpack(fmt, bytes)
bytes = [ bytes[i] ^ pad[i] for i in xrange(len(bytes)) ]
return struct.pack(fmt, *bytes)
评论列表
文章目录