简单的加密解密的函数(js)

加密
    function compile(code) {
        var c=String.fromCharCode(code.charCodeAt(0)+code.length);
        for(var i=1;i<code.length;i++){
            c+=String.fromCharCode(code.charCodeAt(i)+code.charCodeAt(i-1));
        }
        return(escape(c));
    }

解密
    function uncompile(code) {
        code=unescape(code);
        var c=String.fromCharCode(code.charCodeAt(0)-code.length);
        for(var i=1;i<code.length;i++){
            c+=String.fromCharCode(code.charCodeAt(i)-c.charCodeAt(i-1));
        }
        return c;
    }


 console.log(compile("ji45+-*积极"));
 console.log((uncompile(compile("ji45+-*积极"))));

猜你喜欢

转载自blog.csdn.net/qq_41642932/article/details/86690028