I converted my code from python 2 to python 3, everything is working well except for this part of the code:
from binascii import unhexlify
def swap_endian_words(hex_words):
'''Swaps the endianness of a hexidecimal string of words and converts to binary string.'''
message = unhexlify(hex_words)
if len(message) % 4 != 0: raise ValueError('Must be 4-byte word aligned')
return ''.join(([ message[4 * i: 4 * i + 4][::-1] for i in range(0, len(message) // 4) ]))
print(swap_endian_words('aabbccdd'))
The console is giving me the output:
TypeError: sequence item 0: expected str instance, bytes found
I think that this is due to the fact that the program cannot iterate over bytes, which the variable message is formatted in. I tried to use .decode() on message, but it did not work.