MD5 was designed by Ron Rivest, who is also the `R' in `RSA'. MD5 is described in rfc1321. C source code is included with the RFC.
John Allen <allen@grumman.com> wrote this implementation of MD5 optimised for size, in 8 lines of perl5:
MD5 creates a 128 bit hash (4 32 bit ints), which is designed so that it should be computationaly expensive to find a text which matches a given hash. ie if you have a hash for document A, H(A), it is difficult to find a document B which has the same hash, and even more difficult to arrange that document B says what you want it to say.
Hashes are used (amongst other things) in digital signatures, it is common to digitally sign a hash of a message rather than the whole message. This is what the block of text at the bottom of a PGP clearsigned document is, the MD5 digest of the message, encrypted with the authors private RSA key.
Actually somewhat amusingly, it is possible to use the above md5 implementation together with the rsa in 3 lines of perl implementation, and Mark Shoulson's pgpacket util (for extracting pgp keys in hex) to produce a PGP compatible signature.
Well it made me chuckle when I got it to work, after I realised I now had enough components to put it together.
John also wrote a SHA in few lines of perl5.