Decoding a bytes sequence – what’s the train of thought when doing it

  python, python-3.x

I have this sequence and I have to decode it, as a complete beginner in Python and in encoding.

enc = b'x80x03}qx00(Kx01Kx01Kx02Kx03Kx03Kx06Kx04G?xc5UUUUUUKx05G?xe0x00x00x00x00x00x00Kx06G?x9cqxc7x1cqxc7x1cKx07G?xc5UUUUUUKx08K$KtG?xb5UUUUUUKnKx07Kx0bG?xe5UUUUUUKx0cG?xb5UUUUUUKrG?xedUUUUUUKx0eK4Kx0fG?xb3xb1;x13xb1;x14Kx10Kx00Kx11G?xcdx89xd8x9dx89xd8x9eKx12G?xcbx9bx9bx9bx9bx9bx9cKx13G?xa4x14x14x14x14x14x14Kx14Xx08x00x00x00discretaqx01Kx15Kx02Kx16Xx02x00x00x00daqx02Kx17G?xe4zxe1Gxaex14{[email protected]?xe4zxe1Gxaex14|Kx1aK2Kx1bKx01Kx1cKx03Kx1dG?xd5UUUUUUKx1eG?xc5UUUUUUKx1fKx01K Kx04K!G?xafxf2xe4x8ex8aqxdeK"Kx04K#Xx04x00x00x00mareqx03u.'

I tried doing it this way

strputere = enc.decode()

print(strputere)

and I get an error

File "encode.py", line 4, in <module>
    strputere = enc.decode()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

I started doing a bit of research, and I found that b stands for bytes.

So my enc variable is a bytes string literal. I’ve looked into .decode() and it seemed like it was a good choice – but it might be not.

I’m a bit confused because it is a bytes string literal, but it contains some characters (such as x80) that I think they are UTF-8 characters.

So, how can I decode this, and what would be the algorithm for that? I would love to understand what happens, I did my research but I’m a bit lost, I’d need some help.

Source: Python-3x Questions

LEAVE A COMMENT