• IDF实验室-简单的js解密


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

    <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>
  • 相关阅读:
    Numpy存字符串
    一个类似于postman的协议测试工具
    freetds设置超时
    学习jQuery
    webpy 使用python3开发
    gdb调试coredump文件
    htop和ncdu
    rqalpha-自动量化交易系统(一)
    perl学习-运算符添加引号
    xss 和 csrf攻击详解
  • 原文地址:https://www.cnblogs.com/duanv/p/4546827.html
Copyright © 2020-2023  润新知