Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'binary': 0.07; 'ascii': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'translate': 0.10; 'command.': 0.16; 'hex': 0.16; 'prefix:': 0.16; 'readable': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'command': 0.22; '>>>': 0.22; 'input': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'instance,': 0.24; 'rid': 0.24; 'sort': 0.25; 'skip:" 30': 0.26; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'lines': 0.31; 'anyone': 0.31; 'file': 0.32; '(most': 0.33; 'guess': 0.33; 'sense': 0.34; 'problem': 0.35; 'convert': 0.35; 'form.': 0.35; 'but': 0.35; 'format.': 0.36; 'sequence': 0.36; 'expected': 0.38; 'form,': 0.38; 'handle': 0.38; 'to:addr:python- list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'back': 0.62; 'email addr:gmail.com': 0.63; 'more': 0.64; 'sense"': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: HEX to ASCII Date: Sun, 06 Oct 2013 21:31:16 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p50849e31.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381087879 news.xs4all.nl 15985 [2001:888:2000:d::a6]:40958 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56278 markotaht@gmail.com wrote: > problem is : Traceback (most recent call last): > File "C:\Users\Marko\Desktop\hacker.org\XOR cypher.py", line 35, in > > 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.