I'm trying to mask a string by encoding it like this:
>>> 'monkey'.encode('utf-16') b'\xff\xfem\x00o\x00n\x00k\x00e\x00y\x00' I then copy \xff\xfem\x00o\x00n\x00k\x00e\x00y\x00 and paste it into a file file.txt.
Then I want to read that file in and decode it.
>>> with open('file.txt', 'rb') as f: >>> bytes_object = next(f).strip() # assume file has only one line >>> bytes_object b'\\xff\\xfem\\x00o\\x00n\\x00k\\x00e\\x00y\\x00' The \'s are being escaped... not what I want.
Decoding does not work as expected.
>>> bytes_object.decode('utf-16') '硜晦硜敦屭へ漰硜〰屮へ欰硜〰履へ礰硜〰' Clearly I am not understanding something here. Is there any way to read and decode a file that has the text \xff\xfem\x00o\x00n\x00k\x00e\x00y\x00?
eval(bytes_object).decode('utf-16')