lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 5/8/07, Neha <jvneha@yahoo.com> wrote:
I need to calculate hash of a string in lua.
How would I do this?

Why do you need to compute the hash of a string in Lua?  Lua's table
already provides a hash data structure.

Assuming that you don't want a hash data structure, you might be
asking about a cryptographic hash function, or message digest.  In
this case, there exist several MD5 implementations in Lua, as well as
a binding to the OpenSSL library in LuaCrypto.

If you don't want a cryptographic hash, then what kind of hash do you
want?  I dare say that there are as many hash functions for strings as
there pebbles on a beach.  Well, not quite that many I guess.  Anyway,
check the links from the Wikipedia page:

http://en.wikipedia.org/wiki/Hash_function#External_links

and of course, Lua hashes strings too:

http://www.lua.org/source/5.1/lstring.c.html#luaS_newlstr

    -Mark