Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Stephen Hansen Newsgroups: comp.lang.python Subject: Re: How to XOR a byte output? Date: Wed, 13 Apr 2016 08:33:51 -0700 Lines: 33 Message-ID: References: <387506b1-b645-4907-a45c-81a8c3043099@googlegroups.com> <1460561631.1014559.577673577.65A97D80@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de dMnBSAWLEM20g4Opzm7GmQFbXPq8ljfRttGfhU8T8dcQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'value,': 0.03; 'encoded': 0.05; 'converts': 0.07; 'correct.': 0.07; 'counting': 0.07; 'subject:How': 0.09; 'integers': 0.09; 'received:internal': 0.09; 'wed,': 0.15; '(1),': 0.16; '(well,': 0.16; '57,': 0.16; '63,': 0.16; 'decode': 0.16; 'hex': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; "range'": 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'byte': 0.18; 'bytes': 0.18; 'integer': 0.18; "shouldn't": 0.18; 'string,': 0.18; '>>>': 0.20; 'ascii': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; '(which': 0.26; 'raw': 0.27; '13,': 0.29; 'notation': 0.29; 'such.': 0.29; 'character': 0.29; 'convert': 0.29; 'skip:b 40': 0.29; 'print': 0.30; 'certainly': 0.30; 'point': 0.33; 'besides': 0.35; 'something': 0.35; 'instead': 0.36; '(and': 0.36; 'to:addr:python- list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'two': 0.37; 'being': 0.37; 'thought': 0.37; 'received:66': 0.38; 'represent': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'header:Message-Id:1': 0.61; 'back': 0.62; 'series': 0.65; 'computers': 0.70; 'want:': 0.84 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=ixokai.io; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=7L0FegWmNk1gj+qkuLZC+3VFGOM=; b=W22IHY ZAV0vmt67GsS1AQPZ+tcajB2vumFYduiHthjbCDBgPSNX4Vl1G/e4lwT5oV060A9 NO2UrRe0epTMaTbvv170hLQd3QtgNcJq+TKu6Ll3Wl4cR+lpM51HXLq8MaVdvwLI 4fPK2obe0al8iqwwku81EvPq4m7Hm0FByBQ04= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=7L0FegWmNk1gj+q kuLZC+3VFGOM=; b=t8AONDU8htfIpIu9bKD2NZjDkOArGixh+wmIi06BxmVjYKu pQIf7d8zJdTYhy1bCHxGC1WqccDAQ94biWUOnEFObg//ZfYbDeAun4YeaBgaBubY ZeR2v8AgHjje2EMFFQuOUlF27CjKKurwI7uS8+T0FAJcbYtnWjTVwu1kJ8c8= X-Sasl-Enc: IuFyeqajaSMwh+6pCvM+oaIScN1OpavFEVgzxwy2stln 1460561631 X-Mailer: MessagingEngine.com Webmail Interface - ajax-7bc02efc In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1460561631.1014559.577673577.65A97D80@webmail.messagingengine.com> X-Mailman-Original-References: <387506b1-b645-4907-a45c-81a8c3043099@googlegroups.com> Xref: csiph.com comp.lang.python:106950 On Wed, Apr 13, 2016, at 06:51 AM, durgadevi1 wrote: > I would like to check with you whether using binascii.hexlify() to > convert the series of bytes into alphabets and integers is correct. To be clear, they already are integers.The \x notation is how you naively represent a byte out of the printable range in ASCII. A byte is a number from 0 to 255, which can also be thought of as 0x00 to 0xFF.. The 'printable range' is those bytes which represent normal characters instead of control codes and such. Computers like showing raw byte data in hex \x (which shouldn't be confused with binascii.hexify) because then each byte concisely fills up exactly 2 (well, 4, counting the \x) characters, instead of some bytes being only one character (1), some being two (10), and some being three (100). You can see the integer value, consider: >>> data = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\\' >>> print data[0] 36 >>> print data[10] 19 >>> list(data) [36, 47, 47, 87, 63, 192, 130, 57, 162, 185, 19, 140, 213, 123, 92] binascii is almost certainly not what you want: that converts arbitrary bytes into an ASCII encoded string, at which point its no longer bytes (and before you did something to it besides displaying it, you'd want to decode it back to bytes again, probably). --Stephen m e @ i x o k a i . i o