Is there a built-in lua hashing function?
Posted: Fri Jul 11, 2008 3:52 pm
I was wondering if MicroMacro/lua has an included hashing function akin to MD5, SHA1, etc? Or do I need to get a 3rd party library to do it?
MicroMacro home
https://www.solarstrike.net/phpBB3/
Code: Select all
-- Generates a random hash with the specified length.
-- If length is less than or equal to zero, or unspecified, 32 bytes will be assumed.
function random_hash(len)
if( len == nil or len <= 0 ) then len = 32; end;
local holder = ""; -- a string for holding our hash temporarily
-- create an array of all acceptable characters that can be put in our hash.
hash_chars = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E",
"F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"};
for i = 1, len do
local index = math.random(1, #hash_chars);
holder = holder .. hash_chars[index];
end
return holder;
end
Code: Select all
printf("Hash: %s", random_hash(16));
Code: Select all
function getPixelInt(hdc, x, y)
local r, g, b = getPixel(hdc, x, y);
local retval = (r * 256 * 256) + (g * 256) + b;
return retval;
end
Code: Select all
-- returns true if the two colors are within 'delta' variation
-- else, returns false
function compareColors(r1, g1, b1, r2, g2, b2, delta)
-- if delta was not set, set it to 10.
if( delta == nil ) then delta = 10; end;
if( math.abs(r2 - r1) <= delta and
math.abs(g2 - g1) <= delta and
math.abs(b2 - b2) <= delta )
return true;
else
return false;
end