尝试将十六进制列表从binascii转换为文本



我一直在尝试转换这个列表:

[54, 57, 54, 100, 55, 48, 54, 102, 55, 50, 55, 52, 50, 48, 54, 102, 55, 51, 48, 100, 48, 97, 54, 54, 54, 57, 54, 99, 54, 53, 50, 48, 51, 100, 50, 48, 54, 102, 55, 48, 54, 53, 54, 101, 50, 56, 50, 55, 55, 52, 54, 53, 55, 51, 55, 52, 50, 101, 55, 48, 55, 57, 50, 55, 50, 99, 50, 48, 50, 50, 55, 50, 54, 50, 50, 98, 50, 50, 50, 57, 48, 100, 48, 97, 55, 48, 55, 50, 54, 57, 54, 101, 55, 52, 50, 56, 54, 54, 54, 57, 54, 99, 54, 53, 50, 57, 48, 100, 48, 97, 54, 54, 54, 57, 54, 99, 54, 53, 50, 101, 55, 51, 54, 53, 54, 53, 54, 98, 50, 56, 51, 48, 50, 57, 48, 100, 48, 97, 55, 51, 55, 52, 54, 49, 55, 50, 55, 52, 52, 50, 55, 57, 55, 52, 54, 53, 50, 48, 51, 100, 50, 48, 51, 48, 48, 100, 48, 97, 54, 53, 54, 101, 54, 52, 52, 50, 55, 57, 55, 52, 54, 53, 50, 48, 51, 100, 50, 48, 51, 52, 51, 51, 51, 48, 48, 100, 48, 97, 54, 50, 55, 57, 55, 52, 54, 53, 55, 51, 50, 48, 51, 100, 50, 48, 50, 50, 50, 50, 48, 100, 48, 97, 54, 50, 54, 57, 54, 101, 52, 50, 55, 57, 55, 52, 54, 53, 50, 48, 51, 100, 50, 48, 50, 50, 50, 50, 48, 100, 48, 97, 55, 55, 54, 56, 54, 57, 54, 99, 54, 53, 50, 48, 55, 51, 55, 52, 54, 49, 55, 50, 55, 52, 52, 50, 55, 57, 55, 52, 54, 53, 50, 48, 50, 49, 51, 100, 50, 48, 54, 53, 54, 101, 54, 52, 52, 50, 55, 57, 55, 52, 54, 53, 51, 97, 48, 100, 48, 97, 50, 48, 50, 48, 50, 48, 50, 48, 54, 50, 55, 57, 55, 52, 54, 53, 53, 52, 54, 102, 52, 49, 54, 52, 54, 52, 50, 48, 51, 100, 50, 48, 55, 51, 55, 52, 55, 50, 50, 56, 54, 54, 54, 57, 54, 99, 54, 53, 50, 101, 55, 50, 54, 53, 54, 49, 54, 52, 50, 56, 55, 51, 55, 52, 54, 49, 55, 50, 55, 52, 52, 50, 55, 57, 55, 52, 54, 53, 50, 57, 50, 57, 48, 100, 48, 97, 50, 48, 50, 48, 50, 48, 50, 48, 54, 50, 55, 57, 55, 52, 54, 53, 53, 52, 54, 102, 52, 49, 54, 52, 54, 52, 50, 48, 51, 100, 50, 48, 54, 50, 55, 57, 55, 52, 54, 164, 53, 52, 54, 102, 52, 49, 54, 52, 54, 52, 50, 101, 55, 50, 54, 53, 55, 48, 54, 99, 54, 49, 54, 51, 54, 53, 50, 56, 50, 50, 54, 50, 50, 55, 50, 50, 50, 99, 50, 48, 50, 50, 50, 50, 50, 57, 48, 100, 48, 97, 50, 48, 50, 48, 50, 48, 50, 48, 54, 50, 55, 57, 55, 52, 54, 53, 53, 52, 54, 102, 52, 49, 54, 52, 54, 52, 50, 48, 51, 100, 50, 48, 54, 50, 55, 57, 55, 52, 54, 53, 53, 52, 54, 102, 52, 49, 54, 52, 54, 52, 50, 101, 55, 34, 54, 53, 55, 48, 54, 99, 54, 49, 54, 51, 54, 53, 50, 56, 50, 50, 50, 55, 50, 50, 50, 99, 50, 48, 50, 50, 50, 50, 50, 57, 48, 100, 48, 97, 50, 48, 50, 48, 50, 48, 50, 48, 54, 50, 55, 57, 55, 52, 54, 53, 53, 52, 54, 102, 52, 49, 54, 52, 54, 52, 50, 48, 51, 100, 50, 48, 54, 50, 55, 57, 55, 52, 54, 53, 53, 52, 54, 102, 52, 49, 54, 52, 54, 52, 50, 101, 55, 50, 54, 53, 55, 48, 54, 99, 54, 49, 54, 51, 54, 53, 50, 56, 50, 55, 54, 50, 50, 50, 50, 55, 50, 99, 50, 48, 50, 50, 50, 50, 50, 57, 48, 214, 48, 97, 50, 48, 50, 48, 50, 48, 50, 48, 54, 50, 55, 57, 55, 52, 54, 53, 53, 52, 54, 102, 52, 49, 54, 52, 54, 52, 50, 48, 51, 100, 236, 48, 54, 50, 55, 57, 55, 52, 54, 53, 53, 52, 54, 102, 52, 49, 54, 52, 54, 52, 50, 101, 55, 50, 54, 53, 55, 48, 54, 99, 54, 49, 54, 51, 54, 53, 50, 56, 50, 55, 50, 50, 50, 55, 50, 99, 50, 48, 50, 50, 50, 50, 50, 57, 48, 100, 48, 97, 50, 48, 50, 48, 50, 48, 50, 48, 54, 50, 55, 57, 55, 52, 54, 53, 55, 51, 50, 48, 51, 100, 50, 48, 55, 51, 55, 52, 55, 50, 50, 56, 54, 50, 55, 57, 55, 52, 199, 53, 55, 51, 50, 57, 50, 48, 50, 98, 50, 48, 50, 50, 50, 48, 50, 50, 50, 48, 50, 98, 50, 48, 54, 50, 55, 57, 55, 52, 54, 53, 53, 52, 54, 102, 52, 49, 54, 52, 25, 52, 48, 100, 48, 97, 50, 48, 50, 48, 50, 48, 50, 48, 55, 51, 55, 52, 54, 49, 55, 50, 55, 52, 52, 50, 55, 57, 55, 52, 167, 53, 50, 48, 50, 98, 51, 100, 50, 48, 51, 49, 48, 100, 48, 32, 54, 50, 54, 57, 54, 101, 52, 50, 55, 57, 55, 52, 54, 53, 50, 48, 51, 100, 50, 48, 50, 55, 50, 48, 50, 55, 50, 101, 54, 97, 54, 102, 54, 57, 54, 101, 50, 56, 54, 54, 54, 102, 55, 50, 54, 100, 54, 49, 55, 52, 50, 56, 54, 102, 55, 50, 54, 52, 50, 56, 55, 56, 50, 57, 50, 99, 50, 48, 50, 55, 54, 50, 50, 55, 50, 57, 50, 48, 54, 54, 54, 102, 55, 50, 50, 48, 55, 56, 50, 48, 54, 57, 54, 101, 50, 48, 54, 58, 55, 57, 55, 52, 54, 53, 55, 51, 50, 57, 48, 100, 48, 97, 55, 48, 55, 50, 54, 57, 54, 101, 55, 52, 50, 56, 54, 50, 55, 57, 55, 52, 54, 53, 55, 51, 50, 57, 50, 48, 48, 100, 48, 97, 55, 48, 55, 50, 54, 57, 54, 101, 55, 52, 50, 56, 54, 50, 54, 57, 54, 101, 52, 50, 55, 57, 55, 52, 54, 92, 50, 57]

文本但是我不能我唯一能转换的十六进制是:

696d706f7274206f730d0a66696c65203d206f70656e2827746573742e7079272c202272622b22290d0a7072696e742866696c65290d0a66696c652e7365656b2830290d0a737461727442797465203d20300d0a656e6442797465203d203433300d0a6279746573203d2022220d0a62696e42797465203d2022220d0a7768696c652073746172744279746520213d20656e64427974653a0d0a2020202062797465546f416464203d207374722866696c652e726561642873746172744279746529290d0a2020202062797465546f416464203d2062797465546f4164642e7265706c61636528226227222c202222290d0a2020202062797465546f416464203d2062797465546f4164642e7265706c616365282227222c202222290d0a2020202062797465546f416464203d2062797465546f4164642e7265706c61636528276222272c202222290d0a2020202062797465546f416464203d2062797465546f4164642e7265706c616365282722272c202222290d0a202020206279746573203d2073747228627974657329202b20222022202b2062797465546f4164640d0a20202020737461727442797465202b3d20310d0a62696e42797465203d202720272e6a6f696e28666f726d6174286f72642878292c202762272920666f72207820696e206279746573290d0a7072696e7428627974657329200d0a7072696e742862696e4279746529

看起来您需要执行另一个转换:您得到的每对字符似乎都表示十六进制编码的ascii码(再次)。如果您执行第二次转换,您将得到一个文本,它是一段Python代码,除了在您提供的列表中似乎有一些超出范围的数字。但是我已经把清单原封不动地留下了。下面的代码将产生一个"█";每当列表中的值不表示十六进制字符时,返回该字符:

lst = [] #  your list comes here
def conv(a):
    try:
        return chr(int(a, 16))
    except ValueError:
        return "█"
result = "".join([conv(chr(lst[i])+chr(lst[i+1])) 
            for i in range(0, len(lst), 2)])
import re
# Make sure to never print r without n
print(re.sub(r"r(?!n)", r"rn", result))

输出为:

import os
file = open('test.py', "rb+")
print(file)
file.seek(0)
startByte = 0
endByte = 430
bytes = ""
binByte = ""
while startByte != endByte:
    byteToAdd = str(file.read(startByte))
    byteToAdd = byt█ToAdd.replace("b'", "")
    byteToAdd = byteToAdd.█eplace("'", "")
    byteToAdd = byteToAdd.replace('b"', "")█
    byteToAdd =█byteToAdd.replace('"', "")
    bytes = str(byt█s) + " " + byteToAd█
    startByt█ += 1
binByte = ' '.join(format(ord(x), 'b') for x in █ytes)
print(bytes) 
print(binByt█)

正如你所看到的,大约有1%的文本在输入列表中有一个坏的对应值。

下面是另一个版本,它包含了列表中超出此转换工作范围的少数条目的映射:

lst = [] #  your list comes here
fix = {
    164: 53,
    167: 54,
    34: 50,
    214: 54,
    236: 50,
    199: 54,
    25: 54,
    32: 97,
    58: 50,
    92: 53
}
def conv(a):
    return chr(fix[a] if a in fix else a)
result = "".join([chr(int(conv(lst[i])+conv(lst[i+1]), 16)) 
            for i in range(0, len(lst), 2)])
print(result)

输出为:

import os
file = open('test.py', "rb+")
print(file)
file.seek(0)
startByte = 0
endByte = 430
bytes = ""
binByte = ""
while startByte != endByte:
    byteToAdd = str(file.read(startByte))
    byteToAdd = byteToAdd.replace("b'", "")
    byteToAdd = byteToAdd.replace("'", "")
    byteToAdd = byteToAdd.replace('b"', "")
    byteToAdd = byteToAdd.replace('"', "")
    bytes = str(bytes) + " " + byteToAdd
    startByte += 1
binByte = ' '.join(format(ord(x), 'b') for x in bytes)
print(bytes) 
print(binByte)

最新更新