Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Create a program that prints the MD5 sum of its source in the form:

MD5 sum of my source is: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

No cheating - you can't just read the source file and compute its sum. The program must not read any external information.

Of course you can use a MD5 library available for your language.

share|improve this question
    
If someone manages to collide MD5 (i.e. h = f(h), where f is a crude "salt" for h with all the code garbage that is needed to print), I think they should be allowed to do that. –  Nick T Dec 19 '13 at 9:40

1 Answer 1

up vote 6 down vote accepted

Python 157 149

r='r=%r;import md5;print "MD5 sum of my source is: "+md5.new(r%%r).hexdigest()';import md5;print "MD5 sum of my source is: "+md5.new(r%r).hexdigest()

Output:

MD5 sum of my source is: bb74dfc895c13ab991c4336e75865426

Verification at ideone

share|improve this answer
    
I'm getting a different md5sum for the source file. –  slackwear Nov 9 '12 at 13:38
    
@slackwear what are you getting? –  Matt Nov 9 '12 at 13:39
    
oh you've edited it again. Right now I get 24ba0a79636297dab8803f571d4e3b44 md.py using md5sum in linux –  slackwear Nov 9 '12 at 13:43
    
@slackwear it looks like you have an extra newline at the end of your source file –  Matt Nov 9 '12 at 13:48
    
I've tried it with and without a trailing newline...maybe i'm missing something here –  slackwear Nov 9 '12 at 13:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.