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


Groups > comp.lang.python > #106940

Re: How to XOR a byte output?

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: How to XOR a byte output?
Date 2016-04-13 23:29 +1000
Message-ID <mailman.71.1460554158.15650.python-list@python.org> (permalink)
References <387506b1-b645-4907-a45c-81a8c3043099@googlegroups.com> <CAPTjJmpuG=ew7FPwhdtsgDyjDc8d_T8-zbWuVxZy_sUUGj+R0Q@mail.gmail.com>

Show all headers | View raw


On Wed, Apr 13, 2016 at 11:18 PM, durgadevi1
<srirajarajeswaridevikrupa@gmail.com> wrote:
>
> The output from the file is given below:
>
> b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\'
>
>
> I used the type() to identify the class and its a byte class.
>
> I saw many \x and thought it might be hex.
>
>
> So, I used binascii.hexlify() and got the following output:
> b'242f2f573fc08239a2b9138cd57b'
>
> Now, this output is being encrypted and I need to perform an XOR operation on it in order to retrieve a secret message.
>
> But, I'm not sure how to code the XOR operation. How do I code that?
>

What you have is a series of bytes. They don't have any obvious
meaning right there, so you're going to have to figure out what to XOR
it with.

Let's just guess that you want to xor with the byte value 0xAA. We can
do that fairly simply, using integer operations.

>>> data = b'$//W?\xc0\x829\xa2\xb9\x13\x8c\xd5{\\'
>>> bytes(b ^ 0xAA for b in data)
b'\x8e\x85\x85\xfd\x95j(\x93\x08\x13\xb9&\x7f\xd1\xf6'

Well, that doesn't look much more intelligible. We can try a few other
byte values pretty easily:

>>> bytes(b ^ 0x17 for b in data)
b'388@(\xd7\x95.\xb5\xae\x04\x9b\xc2lK'
>>> bytes(b ^ 0x9D for b in data)
b'\xb9\xb2\xb2\xca\xa2]\x1f\xa4?$\x8e\x11H\xe6\xc1'
>>> bytes(b ^ 0xE2 for b in data)
b'\xc6\xcd\xcd\xb5\xdd"`\xdb@[\xf1n7\x99\xbe'

but it still doesn't look very promising. You're going to need to know
the key - the byte value, or sequence of byte values, to XOR with.

ChrisA

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