Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69635
| Date | 2014-04-03 21:31 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: converting strings to hex |
| References | <c23e9bfd-63f4-4381-b3e2-a75cb87c8293@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8874.1396578707.18130.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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