converting strings to hex

dave em daveandem2000 at gmail.com
Thu Apr 3 22:10:16 EDT 2014


Hello,

I am taking a cryptography class and am having a tough time with an assignment similar to this.

Given plain text message 1 and cipher 1 compute cipher 2 for message 2

Work flow will be:
- figure out the key
- use key to compute c2

So this is what I have so far and am getting nowhere fast.  I could use a little help on this one.

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.


####  Python 2.7###

m1text="my test message"
print( m1text + ' in hex is ')
print m1text.encode("hex")
m1 = m1text.encode("hex")
c1=0x6c73d5240a948c86981bc294814d 

k=m1^c1
print( 'the key = ' )
print hex(k)

This code yields the following:

my test message in hex is 
6d792074657374206d657373616765
Traceback (most recent call last):
  File "/media/.../Crypto/Attackv2.py", line 10, in <module>
    k=m1^c1
TypeError: unsupported operand type(s) for ^: 'str' and 'long'

Any help is most appreciated.

Dave



More information about the Python-list mailing list