IS.HASH.MD5 Generating with UniBASIC DIGEST Command
The MD5 message-digest algorithm is a widely used cryptographic hash function producing a 128-bit (16-byte) hash value, typically expressed in text format as a 32-digit hexadecimal number. MD5 has been utilized in a wide variety of cryptographic applications and is also commonly used to verify data integrity.
While not as secure as SHA1, it is still used in many places for data integrity, version control, and other features that need unique one-way signatures.
MD5 Function
MD5 processes a variable-length message into a fixed-length output of 128 bits. The input message is broken up into chunks of 512-bit blocks (sixteen 32-bit words); the message is padded so that its length is divisible by 512. The padding works as follows: first a single bit, 1, is appended to the end of the message. This is followed by as many zeros as are required to bring the length of the message up to 64 bits fewer than a multiple of 512. The remaining bits are filled up with 64 bits representing the length of the original message, modulo 264.
MD5("The quick brown fox jumps over the lazy dog")
9e107d9d372bb6826bd81d3542a419d6
MD5 will detect even small changes in the string and cause the returned hash value to change. You can always read more about MD5 at:
https://en.wikipedia.org/wiki/MD5
UniBASIC Hashing
UniBASIC comes with hashing extensions in the form of DIGEST(). The DIGEST has SHA1 built-in. This allows you to use code like [Figure 1].
MD5.MESSAGE = "The quick brown fox jumps over the lazy dog" ret = DIGEST('MD5',MD5.MESSAGE, 1, SHA1.HASH) CRT SHA1.HASH : ' = 9e107d9d372bb6826bd81d3542a419d6 '
The subroutine found with this article is based on the code above, but has be structured to be interchangeable with non-UniBASIC versions of the MD5 subroutine also found on the International Spectrum Website.
Example
MD5.MESSAGE = "The quick brown fox jumps over the lazy dog" CALL IS.HASH.MD5(MD5.MESSAGE,HASH.VALUE) * TEST.VALUE = "9e107d9d372bb6826bd81d3542a419d6" CRT HASH.VALUE : " =" : TEST.VALUE :" - " IF (HASH.VALUE EQ TEST.VALUE) THEN CRT "Ok" END ELSE CRT "Failed" END
Output
9e107d9d372bb6826bd81d3542a419d6 = 9e107d9d372bb6826bd81d3542a419d6 - Ok