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>
时间: 2024-08-29 15:23:33

IDF实验室-简单的js解密的相关文章

IDF实验室-简单编程-字符统计 writeup

题目地址:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=37 网站:http://ctf.idf.cn/game/pro/37/ 主要是要有2秒的限制.写个python 脚本. 1 #!usr/bin/env python 2 #!coding=utf-8 3 4 import requests 5 import re 6 __author__ = 'zhengjim' 7 8 9 url = 'http://ctf

IDF实验室-简单编程-特殊的日子 writeup

题目:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=50 题目提示要爆破,代表加密应该是不可逆的. 密文:4D1FAE0B 只有八个字符.容易猜测是CRC32加密的. python有直接可以用的模块binascii py代码: #!usr/bin/env python #!coding=utf-8 __author__ = 'zhengjim' import binascii flag = 0x4D1FAE0B fo

IDF实验室-简单的ELF逆向 writeup

题目:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=39 下载得到ElfCrackMe1文件,直接用IDA打开. 最早想到的是 function一路F5下去.可以看到关键的main函数 int __cdecl main(int argc, const char **argv, const char **envp) { int v3; // [email protected] const char **v4; // [

IDF 实验室部分题目WriteUp

前天花了一个下午的时间刷了几道IDF实验室的题目, 这个网站实在是有点冷清, 题目也比较少, 所以就被我和师兄们刷榜了2333... 因为我最先开始做, 所以就干脆刷到第一去了. 题目很水, 切莫见怪. 牛刀小试 http://ctf.idf.cn/index.php?g=game&m=list&a=index&id=16 莫尔斯密码: 网上有转换器, 转换后去空格全小写就是flag. flag: wctf{morseode} ASCII码而已: 这是Unicode码好吧...随便

IDF实验室-CTF训练营-牛刀小试CTF

自从开始玩CTF后,发现这个游戏还是比较有意思,发现了一个练习场地IDF实验室:http://ctf.idf.cn/ 刷刷里面的题目,今天完成了其中的牛刀小试,分享一下解题思路: 1. 被改错的密码 题目为: 从前有一个熊孩子入侵了一个网站的数据库,找到了管理员密码,手一抖在数据库中修改了一下,现在的密码变成了 cca9cc444e64c8116a30la00559c042b4,那个熊孩子其实就是我!肿么办求解!在线等,挺急的.. PS:答案格式wctf{管理员原密码} 第一眼看上去cca9cc

IDF实验室解题学习笔记1

1.图片里的英文 图片可以有很多种打开方式,破解该题,需将图片下载下来. 对于图片,我们可以使用图片编辑软件,进行各种调明暗,变色调等操作. 我们还可以使用2进制或者16进制的文件打开方式打开.该图使用16进制方式打开后,可以察觉到rar文件类型的标记,所以我们可以将其使用rar方式打开. 知识点:文件的不同打开方式:16进制文件中对于各种文件格式的标志的识别,CSDN上有相关介绍. 地址:http://blog.csdn.net/adparking/article/details/559990

简单的JS表单验证效果代码

简单的JS表单验证代码:表单验证几乎是不可缺少的,有的表单验证是在后台完成的,有的则是使用JavaScript在在前端完成基本的验证,这样可以有效的减轻服务器的压力,下面就介绍一下JS实现的最简单的表单验证.代码实例如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://w

简单的JS运动封装实例---侧栏分享到

1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <title>无标题文档</title> 6 <style> 7 #div1 {width: 100px; height: 200px; background: red;

简单的js表单验证框架

/** * 通常在我们的HTML页面表单中有大量的数据验证工作, * 免不了要写很多验证表单的js代码,这是一项非常繁琐 * 枯燥的工作.很多程序员也会经常遗漏这项工作.当然 * 一些JavaEE框架中有一些比较好的验证框架提供给我们 * 使用,但是也是需要很多繁琐的配置,页面查看起来也 * 不是很方便.一般程序员使用的也不多.所以写了这一 * 段JavaScript代码提供给大家使用.算是一个简单的 * JavaScript验证框架吧.使用起来很简单,配合下面几 * 种标签使用,能实现大多数表