0

我在解码 HEX 字符串时遇到了一些麻烦,我得到了

    Traceback (most recent call last):
key : a

output = output.decode("hex")
HEX : 
  File "C:\Python27\lib\encodings\hex_codec.py", line 42, in hex_decode
 output = binascii.a2b_hex(input)
TypeError: Odd-length string

我尝试了一些方法来解决它,但似乎没有任何效果。此外,当迭代某些打印而不解码时,for 循环在 g 字母处崩溃。任何线索?

My Code:
key1 = "1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736"
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
        'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
key1 = int(key1, 16)
for letter in alphabet:
    print "-------------------"
    print "key : " + letter
    print "-------------------"
    print "HEX : "
    key2 = int(letter, 16)
    result = key1 ^ key2
    result =hex(result)
    output = str(result)
    output = output.decode("hex")
    print output
4

1 回答 1

0

如果字符串的长度是偶数,但仍然显示奇数类型错误,则必须是由于前导或尾随空格所致。要删除它们: s=" abcd " s.strip()

要仅删除尾随空格,请使用 s.rstrip()

于 2015-07-06T18:07:23.607 回答