I have an AES256 encrypted message as a string. The message consists of the IV (16 bytes HEX numbers so total 32 characters in the string) and 64 bytes HEX payload (128 characters). Therefore its a single 160 character string consisting of HEX numbers 00, e0, f2 etc. Why is it string? Its received from an another device as a string.
Now I break up the encrypted message to the IV and payload using the code 'iv = encrypted[:16]'. The IV is only zeroes (for testing purposes). If I use iv = bytes.fromhex(iv) I can print the iv as b'\x00\x00\x00... which is what I expect.
But when I do the same for the payload message starting with 9ed57a..., I would expect to get b'\x9e\xd5\x7a... etc, instead I get b'\x9e\xd5z_\xe3.... What do those extra characters (z_) mean and why does the next byte seem to be totally different than what I have in my original string?
The print would not be a problem of course, but when I use AES.decrypt I get garbage, even when I'm sure that I have the same password in both the sending and the receiving end of my setup. If my code is totally wrong, I would very much appreciate some help to correctly implement what I'm trying to do here.
Edit:
I have been trying something else now, I'm trying to turn the string of HEXes into an array of bytes using a loop. It seems to work right until passing it to the decrypting function. I get the message "ValueError: Input strings must be a multiple of 16 in length" which I don't understand since my input string is exactly 64 characters long (when printing len(msg)). The message is all weird characters, but since it's parsed from standard hexadecimal values ranging from 0x00 to 0xff, why doesn't it work?
Python doesn't print nicely printable characters as escape sequences, but rather as their ASCII counterpart. When you look into an ASCII table, you will see that \x7a or 0x7a corresponds to a lowercase z.
Not all bytes can be printed this way. For example all byte values below 0x20 are unprintable control bytes.
Converting string of Hex numbers to hex for pycrypto (Python 3.4)