Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: How to XOR a byte output? Date: Wed, 13 Apr 2016 23:29:15 +1000 Lines: 46 Message-ID: References: <387506b1-b645-4907-a45c-81a8c3043099@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de /1tQ7dtjRrhwAZzyUesLNw5h3YM/ArQmddegpG2iXAvA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'value,': 0.03; 'that?': 0.05; 'bytes.': 0.07; 'cc:addr:python-list': 0.09; 'subject:How': 0.09; 'xor': 0.09; 'output': 0.13; 'wed,': 0.15; '2016': 0.16; 'data)': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'operation.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'byte': 0.18; 'integer': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fairly': 0.22; 'skip:b 30': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'figure': 0.27; 'message-id:@mail.gmail.com': 0.27; 'sequence': 0.27; 'values': 0.28; '13,': 0.29; 'skip:b 40': 0.29; "i'm": 0.30; 'code': 0.30; 'class.': 0.30; 'guess': 0.31; 'class': 0.33; 'message.': 0.33; 'operations.': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'so,': 0.35; 'skip:b 50': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'there,': 0.37; 'received:209.85.213': 0.37; 'thought': 0.37; 'received:209': 0.38; 'data': 0.39; 'sure': 0.39; 'still': 0.40; 'identify': 0.61; 'more': 0.63; 'series': 0.65; 'encrypted': 0.66; 'below:': 0.71; 'secret': 0.72; 'obvious': 0.76; 'saw': 0.77; 'chrisa': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=CHY9kkXFDmHhjip9D0jQ5Cgr/vIDNHF9miTnjVwKst0=; b=DGYRCcZOMOWgtSFJ0JsGOMxhWGkcwV5ppQXCncBFcvCA6C96vRffDlnwUuC2FZW7ZM NxkeAPPmKKYGwNFdTDc25a8s20g6jNSesqhGdibczmfe3q05EjmJiFH9jg/aWtnyCmhz 1vnUCH29ikIvuXL7K/4ufGvn3abM1sKM96WWvYPzSzUFYPNLe36qAsqW63F9NirLALwg +jRKhOi+nO9ozjK+dMKixDcbmyqsTEyf5spKnecpyRe1ujjr5wV9z4VmpCUyOHYXqaz1 Ng7bmCciQ20NRzABewbZTe8ItBq9EKUtheaKVffYqXlQIl9X2seFxealTfVFipVzc1i0 Jvrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=CHY9kkXFDmHhjip9D0jQ5Cgr/vIDNHF9miTnjVwKst0=; b=AhVP6tr46Zt3eM3CNs3+PNjU8uJ9ZH2a1KtUbSmyezAoQlBFIvxVI98LrEXc9a9Ork tEjNFtRVc4YfJYnmUMRLiByixykGmvTrou50kktVwwvyEXebMcn/khOtxcKYU6n8xzsr MKKM/8Bt9CWFe0UI0Un1r61fyzuDl4rf3pRarXVludTjTBbtYHtJuTPorftF66Me5yep QbqE9VMwQfdUNvZx7Dt48c6X2wa5eQDbAr6wErQ3YfuC+J6Xr92yuJUWKUZhETuWAENe yWZSqgP21xEu/DcUGsKoQwSlGe3QQTzhXPdaplB68DM7An1jMhN3iSdo1a/RVEicPqJE HG+Q== X-Gm-Message-State: AD7BkJJlCxhp2+QimSBEsF3ehOUyhsfx3veAw+Kj/nakC2UR1pJecml5OB07Q2j2cwmDL5l4PxngTc/wMmjcxQ== X-Received: by 10.50.112.169 with SMTP id ir9mr31583847igb.92.1460554155170; Wed, 13 Apr 2016 06:29:15 -0700 (PDT) In-Reply-To: <387506b1-b645-4907-a45c-81a8c3043099@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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <387506b1-b645-4907-a45c-81a8c3043099@googlegroups.com> Xref: csiph.com comp.lang.python:106940 On Wed, Apr 13, 2016 at 11:18 PM, durgadevi1 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