Possible Duplicate:
Generate a Hash from string in Javascript/jQuery
Can anyone suggest a simple (i.e. tens of lines of code, not hundreds of lines) hash function written in (browser-compatible) JavaScript? Ideally I'd like something that, when passed a string as input, produces something similar to the 32 character hexadecimal string that's the typical output of MD5, SHA1, etc. It doesn't have to be cryptographically secure, just reasonably resistant to collisions. (My initial use case is URLs, but I'll probably want to use it on other strings in the future.)
Check out this MD5 implementation for JavaScript. Its BSD Licensed and really easy to use. Example:
There are many realizations of hash functions written in JS. For example:
If you don't need security, you can also use base64 which is not hash-function, has not fixed output and could be simply decoded by user, but looks more lightweight and could be used for hide values: http://www.webtoolkit.info/javascript-base64.html
Check out these implementations
I didn't verify this myself, but you can look at this JavaScript implementation of Java's String.hashCode() method. Seems reasonably short.
This article explains simple hash functions in some detail and provides some sample code (in C) that is pretty straighforward. Looks like Bob Jenkins' hash function could be appropriate for your needs (this Dr Dobbs article has more details and a survey of other hash functions, both of which could be helpful).