Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56278

Re: HEX to ASCII

From Peter Otten <__peter__@web.de>
Subject Re: HEX to ASCII
Date 2013-10-06 21:31 +0200
Organization None
References <cb7a622a-18f7-4f7d-a5ca-d1e45d0ba426@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.792.1381087879.18130.python-list@python.org> (permalink)

Show all headers | View raw


markotaht@gmail.com wrote:

>  problem is : Traceback (most recent call last):
>   File "C:\Users\Marko\Desktop\hacker.org\XOR cypher.py", line 35, in
>   <module>
>     print("Key-" + str(võti) + ": " + str("".join(tulemus2)))
> TypeError: sequence item 0: expected str instance, bytes found
> 
> If i  take away the join command i get this:
>  Key-00000000: [b'u', b'o', b'\x00', b'\x1d', b' ', b'|', b'N', b'\x0f',
>  b'9', b'j', b'K', b'J', b'&', b'#', b'A', b'K', b'5', b'k', b'_',
>  b'\x1e', b',', b'j', b'\x0c', b'\x08', b'i', b'(', b'\x06', b'\\', b'r',
>  b'3', b'\x1f', b'V', b's', b'9', b'\x1d']
> 
> the Key-00000000 is the key im using to decrypt the code. everything else
> is generated by the decrytion process and the unhexlify command. So my
> guess is, the join command cant handle the b"u" type of format. how can i
> get rid of the b.

On the contrary, you need one more b prefix:

>>> tulemus2 = [b'u', b'o', ...]
>>> b"".join(tulemus2)
b'uo\x00\x1d |N\x0f9jKJ&#AK5k_\x1e,j\x0c\x08i(\x06\\r3\x1fVs9\x1d'

> Or does anyone have a better idea how to translate HEX into ASCII and sort
> out the lines that make sense

That is very likely, but you have to be specific about the input data and 
what "makes sense" as the output.

If you start with a hexdump of binary data you already have the human-
readable form, and binascii.unhexlify() will convert it back to the 
"unreadable" binary form.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

HEX to ASCII markotaht@gmail.com - 2013-10-06 12:07 -0700
  Re: HEX to ASCII Peter Otten <__peter__@web.de> - 2013-10-06 21:31 +0200
  Re: HEX to ASCII MRAB <python@mrabarnett.plus.com> - 2013-10-06 20:36 +0100
  Re: HEX to ASCII Piet van Oostrum <piet@vanoostrum.org> - 2013-10-06 21:27 -0400
    Re: HEX to ASCII markotaht@gmail.com - 2013-10-07 06:51 -0700
      Re: HEX to ASCII Piet van Oostrum <piet@vanoostrum.org> - 2013-10-07 11:52 -0400
        Re: HEX to ASCII markotaht@gmail.com - 2013-10-08 01:12 -0700
  Re: HEX to ASCII markotaht@gmail.com - 2013-10-07 06:54 -0700
    Re: HEX to ASCII Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-07 15:16 +0100
      Re: HEX to ASCII markotaht@gmail.com - 2013-10-08 01:13 -0700
        Re: HEX to ASCII Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-10-08 09:25 +0100

csiph-web