IS.HASH.SHA1: Generating with UniBASIC DIGEST command
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 as 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 an 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")
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:
UniBASIC comes with hashing extensions in the form of DIGEST(). The DIGEST has SHA1 built-in. This allows you to use code like the example below.
SHA1.MESSAGE = "The quick brown fox jumps over the lazy dog" ret = DIGEST('SHA1',SHA1.MESSAGE, 1, SHA1.HASH) CRT SHA1.HASH : ' = 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12
The subroutine found with this article is based on the code above, but has been structured to be interchangeable with non-UniBASIC versions of the SHA1 subroutine also found on the International Spectrum Website at: http://www.intl-spectrum.com/resource/756/default.aspx.
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