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;
}

posted @ 2020-02-27 09:15  哥,我还要  阅读(253)  评论(0编辑  收藏  举报