mardi 3 mars 2015

TypeError: Odd-length string while decoding hex string and iteratin with for loop only to one point in list

i have some troubles with decoding HEX strings , im getting



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


I tried some methods to solve it but nothing seems to work. Also when im iterating some print's without decoding thing, for loop crashes at g letter. any clues ?



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

Aucun commentaire:

Enregistrer un commentaire