Change your loop to only loop while $v < 42, and then when the md5 matches, set $v to be the number of copies of "gonna" in the text. ( * ) Print the final string at the end.
If you had a good random generator then with very high probability this program would be correct, although it is unable to run in any reasonable time.
* There are exactly 42 copies of "gonna" in that text. Did God speaking through Douglas Adams subtly rickroll all of us?
The odds of another one with under 2k bytes and exactly 42 copies of "gonna" is a lot higher than having one with 43 copies of "gonna".
In a code golf competition, one character matters. Therefore the odds are that you should use "<" not "==" here.
Sorry for all the silly questions, I'm curious, but my cryto knowledge is weak.
Let's setup what is valid in the string and we can go from there.
a-z | 26 characters
A-Z | 26 characters again
\x20| 1 character, space
.,' | 3 characters for punctuation
() | 2 characters
\n | 1 more character
Now these describe just a string that is very similar to the original pastebin (with a few extra characters). If we were to consider all possible 1943 byte strings it'd be fairly different.So we've now got that we're looking at strings with 59 distinct characters in them. That means we can consider that it encodes log2[59^1943] bits of information, which comes out to 11429.975..., let's just call that 11430 bits. An md5sum contains 128bits, and we're after ones that match just the string we're after. We've already figured out that there should be 2^11430 possible 1943 character strings. So let's divide the possible choices by the number of possible md5sums and we can get a rough idea.
(2^11430)/(2^128) => 2^(11430-128) => 2^11302
Throwing this in a calculator since I don't want to flood HN with a gigantic number, that comes out to about 1.74 * 10^3402 possible strings that will match the MD5.This is just an approximation and I bet I made a mistake on the math somewhere.