Almost a workday...
Apr. 29th, 2012 08:54 amThe feet hit the floor at 5:30 am for a second day in a row, and staying away from the crypto homework was, for me, like staying away from the second cigarette of the day, which is to say, not bloody likely. (Back when I used to smoke—especially after I had begun to seriously think about quitting after having failed to do so several times—I noticed that I could get along pretty well without that first cigarette until some time in the afternoon. After that, however, I was effectively powerless to stop the craving for a second, etc.)
Probably what did it was a hint dropped about tackling the extra-credit homework problem, whose point was to examine a series of supposedly random numbers and then supply the number following the last number shown. The hint suggested that representing the numbers in binary might help. So I wrote a quick program to print all the numbers in binary and bingo! I immediately noticed the recurrence of a rather long sequence of '1's, and the rest was easy.
Having so easily dispatched what, in my mind, was supposed to be the hardest problem in the set, I turned my attention to the remaining problem, the point of which was to drive home, to the student, why a particular method of calculating a string's hash was flawed.
Now, calculating a hash for a string is a little like taking the string's "fingerprint." And if the hash is calculated competently, the hash will change a lot and unpredictably if you change the original string in any way. This also means if you know the hash, it's (very, very) hard to figure out what the original string is. It also means you can electronically send a message such as "Your order is now ready" along with the message's hash, and the recipient can't claim the message actually said "Your order is not ready", because the hash of the alleged message won't match the original, but I digress...
After a few minutes of thinking about the problem, I realized I had imagined it to be much more complicated than it was. To solve the problem, you had to figure out what the weakness in the calculation was, and then write a function that took a string as input and then changed it so that the new string's hash value would be the same as that of the original string.
It took me a while (mostly because I don't know Python that well), but I figured out a one-line solution and thereby completed the problem set. I am feeling positively accomplished.
So now, with my swelled head, I should sit down and get to work. I've got 2,900 words due on Tuesday, 5,000 words due the end of the week, and about 1,500 words due in the foreseeable future (like, by tomorrow night).
And it's time to start packing, again, as well.
Never a dull moment around here, let me tell you!
Probably what did it was a hint dropped about tackling the extra-credit homework problem, whose point was to examine a series of supposedly random numbers and then supply the number following the last number shown. The hint suggested that representing the numbers in binary might help. So I wrote a quick program to print all the numbers in binary and bingo! I immediately noticed the recurrence of a rather long sequence of '1's, and the rest was easy.
Having so easily dispatched what, in my mind, was supposed to be the hardest problem in the set, I turned my attention to the remaining problem, the point of which was to drive home, to the student, why a particular method of calculating a string's hash was flawed.
Now, calculating a hash for a string is a little like taking the string's "fingerprint." And if the hash is calculated competently, the hash will change a lot and unpredictably if you change the original string in any way. This also means if you know the hash, it's (very, very) hard to figure out what the original string is. It also means you can electronically send a message such as "Your order is now ready" along with the message's hash, and the recipient can't claim the message actually said "Your order is not ready", because the hash of the alleged message won't match the original, but I digress...
After a few minutes of thinking about the problem, I realized I had imagined it to be much more complicated than it was. To solve the problem, you had to figure out what the weakness in the calculation was, and then write a function that took a string as input and then changed it so that the new string's hash value would be the same as that of the original string.
It took me a while (mostly because I don't know Python that well), but I figured out a one-line solution and thereby completed the problem set. I am feeling positively accomplished.
So now, with my swelled head, I should sit down and get to work. I've got 2,900 words due on Tuesday, 5,000 words due the end of the week, and about 1,500 words due in the foreseeable future (like, by tomorrow night).
And it's time to start packing, again, as well.
Never a dull moment around here, let me tell you!