zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    centos下nginx的启动
    CentOS7.0安装Nginx 1.7.4
    序员的自我修养
    消息队列 rabbitMQ 的一些操作
    centos linux7的一些操作
    Windows 10 Install rabbitmq-server-3.6.9
    Redis 3.2.100 Windows 32位下载
    Redis配置文件详解
    yii2优化
    mysql中的schema 等价于database,相当于一个数据库
  • 原文地址:https://www.cnblogs.com/duanv/p/4546827.html
Copyright © 2011-2022 走看看