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.
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:
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:
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.
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
2fd4e1c67a2d28fced849ee1bb76e7391b93eb12 = 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12 - Ok