converting strings to hex

D

dave em

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
 
T

Tim Chase

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
'0x4d1553a14172e0acebfd68b1f5e628L'


-tkc
 
M

Mark H Harris

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

hi Dave, if your instructor wanted you to work on this with other people
she would have made it a group project and ordered pizza for everyone.

I'll give you some credit, that last couple of folks that wanted help
with their homework here could not bring themselves to admit they wanted
help with their homework. :)

"HAL, please help me with my homework!"

"I'm sorry, Dave, I can't do that..."

"HAL!!?"

"I'm sorry, Dave, I just can't do that..."


marcus
 
D

dave em

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




'0x4d1553a14172e0acebfd68b1f5e628L'





-tkc

Thanks, got it. Sometimes the simple things can be difficult.

Dave
 
M

Mark H Harris

Thanks, got it. Sometimes the simple things can be difficult.

Dave

You haven't seen nothing yet, wait till M.L. catches you on the flip
side for using gg. {running for cover}

marcus
 
J

James Harris

Mark H Harris said:
hi Dave, if your instructor wanted you to work on this with other people
she would have made it a group project and ordered pizza for everyone.

I'll give you some credit, that last couple of folks that wanted help with
their homework here could not bring themselves to admit they wanted help
with their homework. :)

YMMV but I thought the OP had done a good job before asking for help and
then asked about only a tiny bit of it. Some just post a question!
"HAL, please help me with my homework!"

"I'm sorry, Dave, I can't do that..."

"HAL!!?"

"I'm sorry, Dave, I just can't do that..."

You might find this interesting.

http://sundry.wikispaces.com/transcript-2001

James
 
M

Mark H Harris

YMMV but I thought the OP had done a good job before asking for help and
then asked about only a tiny bit of it. Some just post a question!

Indeed they do. Its a little like negotiating with terrorists. As
soon as you negotiate with the first one, you then must negotiate with
all of them. Bad plan.
The OP was soooo close, that to give him the help is immoral for two
reasons: 1) it deprives him of the satisfaction of accomplishing the
solution to the puzzle himself, and 2) it deprives the instructor
(whoever she is) of the teachable moment. There is something she is
trying to get Dave to learn, and she really *does* want him to go
through the entire exercise on his own.
Other than that, I give the OP credit for honesty and the good 'ol
college try. But next time I'd like to see Dave post the problem (and
his own solution) and then let the professional Cpython community pipe
up on enhancements, or challenges. That way the OP learns twice.

Indeed I do. I was thirteen when Odyssey came out. I was so impressed
with the ship, and yet so disappointed with HAL. My favorite line, "I'm
sorry, Dave, I'm afraid I can't do that," *must* have the word 'afraid'
in there; the HAL 9000 not only had mental illness, &will, but also
classic controlled emotion... but HAL's soft confident assured voice
pattern was fabulous, wasn't it? My second favorite line was, "Look
Dave, I can see you're really upset about this," as Dave was unplugging
HAL's neural net. Classic.

It was not until my later career at IBM did I realize that 'HAL' was one
letter -0ff from 'IBM'; just never thought about it before. Hilarious.
Wasn't it interesting that Kubrick and Clarke were concerned about
machines acquiring will and emotion (or mental illness) before anyone
got those von Neumann processors to 'think' in the first place?
Which, of course, because of the negative answer to the
Entscheidungsproblem is not possible.

This was a passion of Alan Turing; machines thinking I mean. We're going
to find that thinking machine IS possible, but that the system is going
to require multiple quantum processors running together (out of phase
with one another) in order to be self-aware. I think it will happen in
my life-time; I'm encouraged with the work so far...


I'm sorry, Dave, I'm afraid I can't do that...

.... Look Dave, I can see you're really upset about this...




marcus
 
C

Chris Angelico

Indeed they do. Its a little like negotiating with terrorists. As soon as
you negotiate with the first one, you then must negotiate with all of them.
Bad plan.

What, you treat student programmers like terrorists?!? Ouch.
The OP was soooo close, that to give him the help is immoral for two
reasons: 1) it deprives him of the satisfaction of accomplishing the
solution to the puzzle himself, and 2) it deprives the instructor (whoever
she is) of the teachable moment. There is something she is trying to get
Dave to learn, and she really *does* want him to go through the entire
exercise on his own.

I strongly disagree. If someone is asking for a hint, it's because
s/he is trying to learn. I'm always willing to help someone learn,
regardless of whether they're going through a course or currently
employed or whatever. Sometimes a small hint can be obtained from the
interpreter itself; but often, it takes a measure of experience to
grok (one of the differences between the expert and the inexperienced
is how quickly a traceback can be read - an expert can often go
straight to the line with the problem); a hint from another Python
programmer can be immensely helpful, as it can include advice as well
as a hard "this works, that doesn't".

ChrisA
 
M

Mark H Harris

If someone is asking for a hint, it's because
s/he is trying to learn. I'm always willing to help someone learn,
regardless of whether they're going through a course or currently
employed or whatever. Sometimes a small hint can be obtained from the
interpreter itself; but often, it takes a measure of experience to
grok (one of the differences between the expert and the inexperienced
is how quickly a traceback can be read - an expert can often go
straight to the line with the problem); a hint from another Python
programmer can be immensely helpful, as it can include advice as well
as a hard "this works, that doesn't".

I accept that. It really depends case-by-case at what point the
person asks for help ( tension is really a good teacher sometimes ) and
at what level the help is provided ( give the hint, but maintain the
tension ).

I particularly agree with your statement above in every venue except
the educational venue where the break-over moment (the teachable moment)
is NOT the moment being queried ! If the student is NOT able to
discover on their own that one 'moment' the teachable moment may be lost
forever, and the student(s) never have the opportunity to visit that
moment again. Now, was this one of those for Dave, who knows. Beats me.

I do appreciate your disagreement, and I think you have a good point.


marcus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top