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: 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 To: dave em Subject: Re: converting strings to hex In-Reply-To: References: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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