Hash Module
#hash.sha1 string hash.sha1(string str)

Returns the SHA1 hash of a string. The resulting value will be a 20-character long hexadecimal string. An SHA1 hash may be useful for verifying data integrity. For example, you can ensure that very large sets of data are exactly the same not only by comparing them byte-for-byte against each other, but simply by comparing that they have the same SHA1 hash; this may prove useful in checking against data corruption or modification.

Example: local hw_hash = hash.sha1("Hello World"); printf("SHA1 for \'Hello World\' is: %s\n", hw_hash); printf("\nEnter a hash for comparison>"); local inp = io.read("*l"); if( inp == hw_hash ) then printf("Congrats! You entered the correct hash.\n"); else printf("Nope. Wrong hash.\n"); end --[[ This snippet will display the hash for the string "Hello World" If the user enters 0a4d55a8d778e5022fab701977c5d840bbc486d0 when prompted, it will display the congrats line, otherwise it informs them the hash was wrong. --]]
#hash.sha1_file string hash.sha1_file(string filename)

Exactly like hash.sha1() except that it computes the hash for a given file rather than an input string.

Page last updated at 2018-09-25 20:47:42


Copyright 2018