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


Groups > comp.lang.python > #69635

Re: converting strings to hex

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'float': 0.07; 'string': 0.09; '"my': 0.09; 'key.': 0.09; 'parameter': 0.09; 'skip:2 30': 0.09; 'cc:addr:python-list': 0.11; '-tkc': 0.16; '16)': 0.16; 'compute': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'magic': 0.16; 'optional': 0.16; 'record,': 0.16; 'wrote:': 0.18; "skip:' 30": 0.19; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'skip:c 30': 0.32; 'text': 0.33; 'but': 0.35; 'charset:us-ascii': 0.36; 'should': 0.36; 'turn': 0.37; 'step': 0.37; 'how': 0.40; 'dave': 0.60; 'first': 0.61; 'to:addr:gmail.com': 0.65; 'here': 0.66; 'received:50.22': 0.84
Date Thu, 3 Apr 2014 21:31:42 -0500
From Tim Chase <python.list@tim.thechases.com>
To dave em <daveandem2000@gmail.com>
Subject Re: converting strings to hex
In-Reply-To <c23e9bfd-63f4-4381-b3e2-a75cb87c8293@googlegroups.com>
References <c23e9bfd-63f4-4381-b3e2-a75cb87c8293@googlegroups.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.8874.1396578707.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1396578707 news.xs4all.nl 2851 [2001:888:2000:d::a6]:57203
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:69635

Show key headers only | View raw


On 2014-04-03 19:10, dave em wrote:
> So my first step is to compute the key.  I suspect my error below
> is because c1 is a float and m1 is a string but I don't know how to
> turn the string into a float.

For the record, "c1" in your example should be an integer/long

It sounds like you want the optional parameter to int() so you'd do

>>> hex_string = "My text message".encode("hex")
>>> hex_string
'4d792074657874206d657373616765'
>>> m1 = int(hex_string, 16)  # magic happens here
>>> m1
402263600993355509170946582822086501L
>>> c1=0x6c73d5240a948c86981bc294814d 
>>> c1
2199677439761906166135512011931981L
>>> k = m1 ^ c1
>>> k
400239414552556350237329405469124136L
>>> hex(k) # as a string
'0x4d1553a14172e0acebfd68b1f5e628L'


-tkc



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


Thread

converting strings to hex dave em <daveandem2000@gmail.com> - 2014-04-03 19:10 -0700
  Re: converting strings to hex Tim Chase <python.list@tim.thechases.com> - 2014-04-03 21:31 -0500
    Re: converting strings to hex dave em <daveandem2000@gmail.com> - 2014-04-03 20:10 -0700
      Re: converting strings to hex Mark H Harris <harrismh777@gmail.com> - 2014-04-03 22:20 -0500
        Re: converting strings to hex dave em <daveandem2000@gmail.com> - 2014-04-03 20:22 -0700
          Re: converting strings to hex Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-04-04 09:14 +0100
  Re: converting strings to hex Mark H Harris <harrismh777@gmail.com> - 2014-04-03 21:38 -0500
    Re: converting strings to hex "James Harris" <james.harris.1@gmail.com> - 2014-04-04 07:16 +0100
      Re: converting strings to hex Mark H Harris <harrismh777@gmail.com> - 2014-04-04 16:33 -0500
        Re: converting strings to hex Chris Angelico <rosuav@gmail.com> - 2014-04-05 09:36 +1100
          Re: converting strings to hex Mark H Harris <harrismh777@gmail.com> - 2014-04-04 18:00 -0500
    Re: converting strings to hex alister <alister.nospam.ware@ntlworld.com> - 2014-04-04 10:07 +0000

csiph-web