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


Groups > comp.lang.python > #106950

Re: How to XOR a byte output?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Stephen Hansen <me+python@ixokai.io>
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 <mailman.78.1460561634.15650.python-list@python.org> (permalink)
References <387506b1-b645-4907-a45c-81a8c3043099@googlegroups.com> <CAPTjJmpuG=ew7FPwhdtsgDyjDc8d_T8-zbWuVxZy_sUUGj+R0Q@mail.gmail.com> <mailman.71.1460554158.15650.python-list@python.org> <b558f9b2-f961-4bf8-b23a-f054b996c09c@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 <me+python@ixokai.io>
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 <b558f9b2-f961-4bf8-b23a-f054b996c09c@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <1460561631.1014559.577673577.65A97D80@webmail.messagingengine.com>
X-Mailman-Original-References <387506b1-b645-4907-a45c-81a8c3043099@googlegroups.com> <CAPTjJmpuG=ew7FPwhdtsgDyjDc8d_T8-zbWuVxZy_sUUGj+R0Q@mail.gmail.com> <mailman.71.1460554158.15650.python-list@python.org> <b558f9b2-f961-4bf8-b23a-f054b996c09c@googlegroups.com>
Xref csiph.com comp.lang.python:106950

Show key headers only | View raw


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

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


Thread

How to XOR a byte output? durgadevi1 <srirajarajeswaridevikrupa@gmail.com> - 2016-04-13 06:18 -0700
  Re: How to XOR a byte output? Chris Angelico <rosuav@gmail.com> - 2016-04-13 23:29 +1000
    Re: How to XOR a byte output? durgadevi1 <srirajarajeswaridevikrupa@gmail.com> - 2016-04-13 06:51 -0700
      Re: How to XOR a byte output? Chris Angelico <rosuav@gmail.com> - 2016-04-14 00:31 +1000
      Re: How to XOR a byte output? Stephen Hansen <me+python@ixokai.io> - 2016-04-13 08:33 -0700
    Re: How to XOR a byte output? Marko Rauhamaa <marko@pacujo.net> - 2016-04-13 17:27 +0300
      Re: How to XOR a byte output? Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-13 09:30 -0600
      Re: How to XOR a byte output? durgadevi1 <srirajarajeswaridevikrupa@gmail.com> - 2016-04-14 01:49 -0700
        Re: How to XOR a byte output? Peter Otten <__peter__@web.de> - 2016-04-14 11:16 +0200
        Re: How to XOR a byte output? Marko Rauhamaa <marko@pacujo.net> - 2016-04-14 12:18 +0300
          Re: How to XOR a byte output? Chris Juried <cjuried@yahoo.com> - 2016-04-14 23:05 +0000
          Re: How to XOR a byte output? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-04-15 08:06 -0400
  Re: How to XOR a byte output? alister <alister.ware@ntlworld.com> - 2016-04-13 16:15 +0000
    [OT] A doubt about a doubt, was Re: How to XOR a byte output? Peter Otten <__peter__@web.de> - 2016-04-13 18:59 +0200
      Re: [OT] A doubt about a doubt, was Re: How to XOR a byte output? Rustom Mody <rustompmody@gmail.com> - 2016-04-13 18:54 -0700
        Re: [OT] A doubt about a doubt Peter Otten <__peter__@web.de> - 2016-04-14 14:26 +0200
  Re: How to XOR a byte output? durgadevi1 <srirajarajeswaridevikrupa@gmail.com> - 2016-04-14 01:32 -0700
  Re: How to XOR a byte output? durgadevi1 <srirajarajeswaridevikrupa@gmail.com> - 2016-04-15 04:46 -0700

csiph-web