1 <script> 2 a=62; 3 4 function encode() { 5 var code = document.getElementById(‘code‘).value; 6 code = code.replace(/[\r\n]+/g, ‘‘); 7 code = code.replace(/‘/g, "\\‘"); 8 var tmp = code.match(/\b(\w+)\b/g); 9 tmp.sort(); 10 var dict = []; 11 var i, t = ‘‘; 12 for(var i=0; i<tmp .length; i++) { 13 if(tmp[i] != t) dict.push(t = tmp[i]); 14 } 15 var len = dict.length; 16 var ch; 17 for(i=0; i<len; i++) { 18 ch = num(i); 19 code = code.replace(new RegExp(‘\\b‘+dict[i]+‘\\b‘,‘g‘), ch); 20 if(ch == dict[i]) dict[i] = ‘‘; 21 } 22 document.getElementById(‘code‘).value = "eval(function(p,a,c,k,e,d){e=function(c){return(c<a?‘‘:e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!‘‘.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return‘\\\\w+‘};c=1};while(c--)if(k[c])p=p.replace(new RegExp(‘\\\\b‘+e(c)+‘\\\\b‘,‘g‘),k[c]);return p}(" 23 + "‘"+code+"‘,"+a+","+len+",‘"+ dict.join(‘|‘)+"‘.split(‘|‘),0,{}))"; 24 } 25 26 function num(c) { 27 return(c<a ?‘‘:num(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36)); 28 } 29 30 function run() { 31 eval(document.getElementById(‘code‘).value); 32 } 33 34 function decode() { 35 var code = document.getElementById(‘code‘).value; 36 code = code.replace(/^eval/, ‘‘); 37 document.getElementById(‘code‘).value = eval(code); 38 } 39 </a></tmp></script> 40 41 42 <textarea id=code cols=80 rows=20> 43 44 </textarea><br /><input type=button onclick=encode() value=编码/> 45 <input type=button onclick=run() value=执行/> 46 <input type=button onclick=decode() value=解码/>
时间: 2024-10-10 12:27:28