IS.HASH.SHA1: Generating SHA1 Values with Generic MultiValue BASIC

In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function designed by the United States National Security Agency and is a U.S. Federal Information Processing Standard published by the United States NIST. SHA1 is used in many places to generate a unique Hash value representing a string or file. It is widely used in place of MD4 and MD5 hash because it has a more secure hash value. While not as secure as SHA256, it is still used in many places for data integrity, version control, and other features that need unique one-way signatures.

SHA1 Function

SHA-1 produces a 160-bit (20-byte) hash value known as a message digest. A SHA-1 hash value is typically rendered as a hexadecimal number, 40 digits long.

SHA1 ("The quick brown fox jumps over the lazy dog")

gives hexadecimal: 2fd4e1c67a2d28 fced849ee1bb76e7391b93eb12

SHA1 will detect even small changes in the string and cause the returned hash value to change. You can always read more about SHA1 at:

https://en.wikipedia.org/wiki/SHA-1

MultiValue BASIC Hashing

Most versions of MultiValue BASIC do not include built-in hashing functions. This requires developers to create their own.

This can be done in pure, generic MultiValue BASIC, but you may see a performance hit depending on how bit math is handled. For hash values like SHA1, the performance issues of generic bit math do not seem to be a problem.

Dave Meagher has done all the work to provide hash functions like SHA1 and MD5 in his FOSS4MV/mvCrypt code on BitBucket:

https://bitbucket.org/foss4mv/mvcrypt

The IS.HASH.SHA1 program attached to this article used Dave's mvCrypt SHA1 code, but formats it so that it is interchangeable with other versions of the IS.HASH.SHA1 < http://www.intl-spectrum.com/resource/755/ISHASHSHA1-Generating-SHA1-values-with-Generic-MultiValue-BASIC.aspx > code on the International Spectrum website.

Example

SHA1.MESSAGE = "The quick brown fox jumps over the lazy dog"
CALL IS.HASH.SHA1(SHA1.MESSAGE,HASH.VALUE)
*
TEST.VALUE = "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"
CRT HASH.VALUE : " =" : TEST.VALUE :" - "
IF (HASH.VALUE EQ TEST.VALUE) THEN
  CRT "Ok"
END ELSE
  CRT "Failed"
END

Output

2fd4e1c67a2d28fced849ee1bb76e7391b93eb12 = 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12 - Ok
NATHAN RECTOR

View more articles
menu
menu