MD5 Cryptographic Hash Function

Function Syntax (LM:MD5 <lst>)
Current Version 1.1
Download MD5-V1-1.lsp
View HTML Version MD5-V1-1.html
Symbol Type Description
lst List List of integer byte values for which to generate hash
Type Description
String 128-bit (16-byte) hash string of 32 hexadecimal digits

Function Description

This cryptographic hash function is an AutoLISP implementation of the MD5 message-digest algorithm developed in 1992 by Ronald Rivest.

A Little Background Information...

In computer science, a hash function is any function which takes variable length data and returns data of a fixed length, known as a 'hash value' or 'checksum'. A cryptographic hash function is a type of hash function mapping data of arbitrary length to a fixed length output, however, with the property that any small change in the input data will (with overwhelming probability) result in an entirely different output. The input data is sometimes referred to as the 'message', with the output known as the 'message-digest'.

Cryptographic hash functions have many applications pertaining to information security & verification due to the incredible unlikelyhood that two messages have the same hash, and the infeasibility of modifying the message without modifying the resulting hash value.

To provide a tangible example: when downloading a file from a server, a hash might be generated for the file data to allow for verification of the file integrity. Upon downloading the file data, the local system can then generate a hash from the downloaded data and compare the generated hash to that provided by the server. Given the vast infeasibility that two different sets of data will generate the same cryptographic hash, one can be confident that if the hash values match, the downloaded file data is unchanged.

There are many Cryptographic hash algorithms, however, the two most commonly used are the MD5 algorithm developed by Ronald Rivest in 1992 (the algorithm implemented by this function), and the SHA-1 algorithm developed by the NSA.

The AutoLISP Implementation

Unfortunately the AutoLISP implementation of this algorithm is not overly efficient as a result of AutoLISP not supporting the use of 32-bit unsigned integers (the integer data-type in AutoLISP is a 32-bit signed integer) which form the base of the MD5 algorithm.

To circumvent this issue, the function represents each 32-bit unsigned integer as a list of binary values before performing the bitwise manipulation instructed by the algorithm. Whereas, were AutoLISP to support the 32-bit unsigned integer, such operations could be more efficiently performed directly on the integer using the lsh, logand, logior & boole AutoLISP functions.

The function published on this page requires a single argument in the form of an arbitrary length list of integer byte values, and will return a fixed-length 128-bit (16-byte) hash string of 32 hexadecimal digits, generated using the MD5 algorithm.


Below are several examples demonstrating the generation of an MD5 hash for various input arguments.

The last two examples differ by only a single character, and yet the two hash strings generated by the function are entirely different, demonstrating the Avalanche Effect of the MD5 algorithm.

_$ (LM:MD5 nil)

_$ (LM:MD5 (vl-string->list "Lee Mac"))

_$ (LM:MD5 (vl-string->list "abc123"))

_$ (LM:MD5 (vl-string->list "abc124"))


increase · reset · decrease

Designed & Created by Lee Mac © 2010