<script type="text/javascript">
var oStr = "中国人";
var obj = compileStr(oStr);
console.log(obj);
var objStr = uncompileStr(obj);
console.log(objStr);
//对字符串进行加密
function compileStr(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 uncompileStr(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;
}
</script>
js前端的字符串加密
最新推荐文章于 2024-10-30 18:24:25 发布