zoukankan      html  css  js  c++  java
  • JavaScript加密解密压缩工具

     1 <script>
     2 a=62;
     3 
     4 function encode() {
     5  var code = document.getElementById('code').value;
     6  code = code.replace(/[
    ]+/g, '');
     7  code = code.replace(/'/g, "\'");
     8  var tmp = code.match(/(w+)/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=解码/>
  • 相关阅读:
    人工智能芯片支持超低功耗器件的推理
    新十年嵌入式音频的五大趋势
    面向汽车应用的硬件推理芯片
    MySQL优化技巧总结
    JAVA集合类汇总
    为什么HashMap初始大小为16,为什么加载因子大小为0.75,这两个值的选取有什么特点?
    ztree 树状图——例
    amazeUI表单提交验证--input框required
    bigcolorpicker 颜色拾取器插件——例
    博客园-去掉皮肤
  • 原文地址:https://www.cnblogs.com/CHEUNGKAMING/p/4081099.html
Copyright © 2011-2022 走看看