简单的js解密

问题

这里这里→ http://ctf.idf.cn/game/web/43/index.php

Write Up

看完题解解得。

题解说这是个加密函数,让我们自己把解密函数写出来就行了。

把网页保存到本地(浏览器右键保存网页即可),看着加密函数写出解密函数;

/**
 * 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 destring = '';
    for (var i = 0; i < string.length - 1; i=i+2) {
      strCode = string.substring(i,i+2);
      var strInt = parseInt(strCode,16);
      strInt = 255 - strInt;
      if (strInt > 127) {
        strInt -= 128;
      }else if (strInt < 128) {
        strInt += 128;
      }
      destring += String.fromCharCode(strInt);
    }
    return destring;
  }
}
document.write(pseudoHash('4a191b4f4d4b4a19491c461b1b1d1b194c1a19194f194a4f4a46484a1d491e48','DECRYPT'));
// document.getElementById('password').value = pseudoHash('4a191b4f4d4b4a19491c461b1b1d1b194c1a19194f194a4f4a46484a1d491e48', 'DECRYPT');

【PS】直接复制的题解的,注意里面的4a啥的不一样了,然后把新的加密后的字符串复制进去,用浏览器打开后得到一串东西,再回到那个正常的界面点个走你,即可得到密码 wctf{jS_decRypt__Eaaasy}

Python Decode

Last updated

Was this helpful?