window Resize
html 測試 左入右出
!>
html 測試 上入下出
!>
html 測試 單入單出
!>
html 測試 左單右單
!>
Javascript 字串 或 文章 編碼加密 String or article encoding and encryption 1
Javascript 字串 或 文章 編碼加密
function encode(str,key) 功能 傳回 字串/文章 編碼加密, str = 需要 編碼加密 字串/文章, key = 密碼。 function decode(str,key) 功能 傳回 將加密編碼還原為 字串/文章, str = 加密後編碼, key = 密碼。 例 : encode("銀行","123456") 傳回 "ad9ff3c40c7372664ff58ce086420010015de271" 例 : decode("ad9ff3c40c....086420010015de271","123456") 傳回 "銀行"
00
字串/文章 編碼加密 String encoding
- function
encode(str,key) { - str=btoa(escape(str));
- var l="";
- for(var c=0;c<key.length;c++){
- l+=key.charCodeAt(c).toString()}
- var g=Math.floor(l.length/5);
- var b=parseInt(l.charAt(g)+l.charAt(g*2)+l.charAt(g*3)+l.charAt(g*4)+l.charAt(g*5));
- var a=Math.ceil(key.length/2);var h=Math.pow(2,31)-1;
- var d=Math.round(Math.random()*1000000000)%100000000;
- l+=d;
- while(l.length>10){l=(parseInt(l.substring(0,10))+parseInt(l.substring(10,l.length))).toString()}l=(b*l+a)%h;
- var e="";
- var k="";
- for(c=0;c<str.length;c++){e=parseInt(str.charCodeAt(c)^Math.floor((l/h)*255));
- if(e<16){k+="0"+e.toString(16)}
- else{k+=e.toString(16)}l=(b*l+a)%h}d=d.toString(16);
- while(d.length<8){d="0"+d} ;
- k+=d;
- return = k; };
將編碼還原 Restore code
- function
decode(encodeStr,key) { - var l="";
- for(var c=0;c<key.length;c++){l+=key.charCodeAt(c).toString() } ;
- var g=Math.floor(l.length/5);
- var b= parseInt(l.charAt(g)+l.charAt(g*2)+l.charAt(g*3)+l.charAt(g*4)+l.charAt(g*5));
- var a=Math.round(key.length/2);
- var h=Math.pow(2,31)-1;
- var d=parseInt(encodeStr.substring(encodeStr.length-8,encodeStr.length),16);encodeStr=encodeStr.substring(0,encodeStr.length-8);
- l+=d;
- while(l.length>10){l=(parseInt(l.substring(0,10))+parseInt(l.substring(10,l.length))).toString()};
- l=(b*l+a)%h;
- var e="";
- var k="";
- for(c=0;c<encodeStr.length;c+=2){
- e=parseInt(parseInt(encodeStr.substring(c,c+2),16)^Math.floor((l/h)*255)); k+=String.fromCharCode(e);l=(b*l+a)%h}
- if(encodeURIComponent(k).charAt(0)=="%" ||
- encodeURIComponent(k).charAt(1)=="%" ||
- encodeURIComponent(k).charAt(2)=="%" )
- {alert("密碼錯誤 \n wrong password")}
- return = unescape(atob(k)) ;
- }
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言