IDF实验室:天罗地网--简单的js解密

地址:
ctf.idf.cn/index.php?g=game&m=article&a=index&id=43
题目:
http://ctf.idf.cn/game/web/43/index.php

和上篇差不多,直接查看源代码,发现

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
        var output = ''  
        return string; 
    }
}
#document.getElementById('password').value = pseudoHash('4e4f484f4c4f1c1e49474a4f48491c4f1a1b4a1a4f4a4b1a4d1c4c1a1b464b4f', 'DECRYPT');

这段代码只有密文和加密部分,没有解密部分(自己编写好了),写C 程序:
#include<stdio.h>
#include<string.h>
void main(void)
{

int str[64]={0x4a,0x49,0x1a,0x4d,0x1c,0x1e,0x1c,0x1a,0x1a,0x4c,0x4f,0x4e,0x4c,0x1b,0x49,0x4a,0x47,0x46,0x46,0x19,0x46,0x1b,0x4f,0x4a,0x4d,0x4d,0x1e,0x47,0x46,0x4c,0x19,0x47};
    char output[64]="";
    int x=0;
    int charCode;

        for (;str[x]!=0; ++x)
        {     
            charCode= str[x];

            charCode = 255 - charCode;
 
            if (128 > charCode)
            {        charCode -= 128;      }
            else if (127 < charCode)
            {        charCode += 128;      }     
               
            output[x]= (char)charCode;   
        }    // Return output

    printf("\n%s\n",output);
    return 0;
}
将结果提交,显示flag.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值