js 문자열hash 암호화

1793 단어
      String.prototype.hashCode = function(){
        if (Array.prototype.reduce){
            return this.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);              
        } 
        var hash = 0;
        if (this.length === 0) return hash;
        for (var i = 0; i < this.length; i++) {
            var character  = this.charCodeAt(i);
            hash  = ((hash<<5)-hash)+character;
            hash = hash & hash; // Convert to 32bit integer
        }
        return hash;
    }
var hash = new String(‘something’).hashCode();

 
다음으로 전송:https://www.cnblogs.com/wrongcode/p/11015660.html

좋은 웹페이지 즐겨찾기