码迷,mamicode.com
首页 > Web开发 > 详细

IDF实验室-简单的js解密

时间:2015-06-02 17:44:54      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

根据加密方法推算解密方法,补全如下

<script>
/**
 * Pseudo md5 hash function
 * @param {string} string
 * @param {string} method The function method, can be ‘ENCRYPT‘ or ‘DECRYPT‘
 * @return {string}
 */
function pseudoHash(string, method) {
  // Default method is encryption
  if (!(ENCRYPT == method || DECRYPT == method)) {
    method = ENCRYPT;
  }
  // Run algorithm with the right method
  if (ENCRYPT == method) {
    // Variable for output string
    var output = ‘‘;
    // Algorithm to encrypt
    for (var x = 0, y = string.length, charCode, hexCode; x < y; ++x) {
      charCode = string.charCodeAt(x);
      if (128 > charCode) {
        charCode += 128;
      } else if (127 < charCode) {
        charCode -= 128;
      }
      charCode = 255 - charCode;
      hexCode = charCode.toString(16);
      if (2 > hexCode.length) {
        hexCode = 0 + hexCode;
      }
      
      output += hexCode;
    }
    // Return output
    return output;
  } else if (DECRYPT == method) {
      var output = ‘‘;
    for(var x=0,y=string.length,charcode,hexcode;x<y;x=x+2){
        hexcode=string.substr(x,2);
        charcode=parseInt(hexcode,16);
        charcode=255-charcode;
        if (charcode<128) {
        charcode += 128;
          }  if (charcode>127) {
        charcode -= 128;
          }
        output+=String.fromCharCode(charcode);
    }
    return output;
    document.write(output);
  }
}
document.write(pseudoHash(461c4a4f461d484e194d471a1b4f4a4b4c4b4f1e1d4d4c491d1a4d19474c1d1b, DECRYPT));
</script>

 

IDF实验室-简单的js解密

标签:

原文地址:http://www.cnblogs.com/duanv/p/4546827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!