function hash(str) local hash = 0 for i = 1, #str do hash = (hash * 31 + string.byte(str, i)) % 65536 end return string.format("%04X", hash) end