首页 > 代码库 > javascript 简单加解密

javascript 简单加解密

 

 //加密function MyEncrypt(txt){    var sb = "";    var rand = 0;    for (var i=0;i<txt.length;i++)    {        item=txt.charCodeAt(i);        rand = Math.floor(Math.random()*item);        sb+=(pad((item - rand).toString(16),2) + pad(rand.toString(16),2));    }    return sb;}//解密function MyDencrypt(txt){    var sb = "";    var hexArray = new Array(255);    var len = txt.length / 2;    for (var i = 0; i < len; i++)    {        hexArray[i] = txt.substr(i * 2, 2);    }    for (var i = 0; i < len; i++)    {        if (i % 2 == 0)            sb+=(String.fromCharCode(parseInt(hexArray[i], 16) + parseInt(hexArray[i + 1], 16)));    }    return sb;}//补零function pad(num, n) {return Array(n-(‘‘+num).length+1).join(0)+num; }

 

javascript 简单加解密