javascript 十进制加密 十六进制加密

来源:互联网 发布:如何移动数据透视表 编辑:程序博客网 时间:2024/06/08 03:01
<html><head><script>
function Encrypt(){
var monyer = new Array();var i;
for(i=0;i<txt.value.length;i++){
   if(Decimal.checked) monyer+="&#"+txt.value.charCodeAt(i)+";";
   else monyer+=txt.value.charCodeAt(i)+",";
}
txt.value=monyer;
}
function Decrypt(){
var monyer = new Array();var i;
if(Decimal.checked){
   var s=txt.value.split(";");
   for(i=0;i<s.length;i++){
    s[i]=s[i].replace('&#','');
    monyer+=String.fromCharCode(s[i]);
   }
}else{
   var s=txt.value.split(",");
   for(i=0;i<s.length;i++)
    monyer+=String.fromCharCode(s[i]);
}
txt.value=monyer;
}
function doit(f){
var monyer=document.getElementById('txt');
if(monyer) monyer.innerText=f(monyer.innerText);
}
function JavaEn(){
var monyer = new Array();var i,s;
for(i=0;i<txt.value.length;i++){
   s=txt.value.charCodeAt(i).toString(16); 
   if(hex.checked) monyer+="\\u"+new Array(5-String(s).length).join("0")+s;
   else if(hex2.checked) monyer+="&#x"+new Array(5-String(s).length).join("0")+s+";";
   else monyer+="\\"+new Array(5-String(s).length).join("0")+s;
}
txt.value=monyer;
}
function JavaDe(){
if(hex.checked){
   var monyer = new Array();var i;
   var s=txt.value.split("\\");
   for(i=1;i<s.length;i++){
    s[i]=s[i].replace('u','');
    monyer+=String.fromCharCode(parseInt(s[i],16));
   }
}
else if(hex2.checked){
   var monyer = new Array();var i;
   var s=txt.value.split(";");
   for(i=0;i<s.length;i++){
    s[i]=s[i].replace('&#x','');
    monyer+=String.fromCharCode(parseInt(s[i],16));
   }
}
else{
   var monyer = new Array();var i;
   var s=txt.value.split("\\");
   for(i=1;i<s.length;i++) monyer+=String.fromCharCode(parseInt(s[i],16));
}
txt.value=monyer;
}
</script></head><body>
<textarea id='txt' name='txt' cols=100 rows=35></textarea><br />
<input type='button' value='10进制加密' onclick='Encrypt()'>
<input type='button' value='10进制解密' onclick='Decrypt()'>
<input name="Decimal" type="checkbox" value="checkbox">
默认为“,”分隔;选中为“&amp;#;”分隔
<br>
<input type='button' value='escape加密' onclick='doit(escape)'>&lt;=&gt;
<input type='button' value='unescape解密' onclick='doit(unescape)'>
<br>
<input type='button' value='16进制加密' onclick='JavaEn()'>
<input type='button' value='16进制解密' onclick='JavaDe()'>
<input name="hex" type="checkbox" value="checkbox">
默认为“\”分隔;选中为“\u”分隔
<input name="hex2" type="checkbox" value="checkbox">
选中为“&amp;#x;”分隔
</body></html>
原创粉丝点击