简单的js解密

本文介绍了JavaScript代码加密的七种方法,包括使用escape()和unescape()函数、转义字符、Microsoft Script Encoder、添加NUL空字符、无用内容混乱、自写解密函数以及错误利用。通过这些技巧,可以增加代码的保密性和拷贝难度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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



源代码:

<html><head><title>简单的js解密</title></head>
<body>
<p>这道题还是从老外那里抄的,老外太牛逼了不然以我的智商累死也编不出这种题啊。。</p>
<p>PS:我只是单纯地把这题抄过来了,还没有做,实在不会啊。。。 = =!</p>
<form id="levelQuest" method="post">
<p>密码:</p>
<p><input type="password" name="password" class="input" id="password"> <input type="submit" class="button" value="走你"></p>
</form>
<p id="errorMessage"></p>
<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) {
    // DECODE MISS
    // Return ASCII value of character
    return string;
  }
}
document.getElementById('password').value = pseudoHash('1e1a4d1e4d1b1d4b4f1e4e4d1a1c4f4e4c4e1b4b471e1c1c4e4d4e471b4d1a19', 'DECRYPT');
</script>
<p id="tip"></p>
</body> 
</html>

解密代码:

<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);
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值