Time33 算法 C#版本

适合拿来做token生成

JAVASCRIPT:

function time33(str) {

var hash = 5381;
for (var i = 0,
len = str.length; i < len; ++i) {
hash += (hash << 5) + str.charAt(i).charCodeAt();
}
return hash & 0x7fffffff;
}

C#:

public long Time33(string str)
{
int hash = 5381;
for (int i = 0,
len = str.Length; i < len; ++i)
{
char[] sub = str.ToCharArray(i, 1);
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(sub);

hash += (hash << 5) + bytes[0];
}
hash &= 0x7fffffff;
return hash;
}

原文地址:https://www.cnblogs.com/upshania/p/12370411.html