I need to generate a substirng that should works as an unique identifier (something like an hash), so with a reduced risk of collisions, for a string in JavaScript. This Hash/Substring however should not exceed 32 bytes of length .
I need this because I've to store it in a Solidity Smart Contract as identifier of that string. I've found many functions to get and Hash code from a string in JavaScript, however is not what I'm looking for.
String.prototype.hashCode = function() {
var hash = 0,
i, chr;
if (this.length === 0) return hash;
for (i = 0; i < this.length; i++) {
chr = this.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
If I have a string like this: "Hello, this is a smart question", I expect an hash that represent the string, for example "hllhsmrtqstin". Could be even smaller then 32 bytes but it's important that does not exeed this lenght, regardless string size.
N.B. I'm not looking for something like sha256, because I need a human readbale hash that could be reconduced to the original string, another example "Hello World" > "hlwld"