converting strings to hex
dave em
daveandem2000 at gmail.com
Thu Apr 3 23:10:21 EDT 2014
On Thursday, April 3, 2014 8:31:42 PM UTC-6, Tim Chase wrote:
> 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
Thanks, got it. Sometimes the simple things can be difficult.
Dave
More information about the Python-list
mailing list