moectf2020 write up for mess

一道简单的编程语言应用题> <

题干给出的加密代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import random
flag = 'moectf{xxxxxxxxxxx}'

digit = ''

for i in flag:
digit += str(ord(i))


i = 0

while i < len(digit):
n = random.randint(0, 128)
if ord('a') <= n <= ord('z') or ord('A') <= n <= ord('Z'):
digit = digit[0:i] + chr(n) + digit[i:]
i += 1

with open('puzzle.txt', 'w') as out:
out.write(digit)

加密后字符串如下

1
1091111A01ruVJl99hw11Qv6i102xCYC1c2B31DIsz1tm212l11A1l610448re11BQ09549115951n154V895F115d49109h1m1210810j11w2A5

这个时候我们就很容易看出加密过程为字符串转ASCII码转字符串再随机插入英文字母啦

故构造逆向代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main(void)
{
char ch[200] = "1091111A01ruVJl99hw11Qv6i102xCYC1c2B31DIsz1tm212l11A1l610448re11BQ09549115951n154V895F115d49109h1m1210810j11w2A5";
int len = strlen(ch);
char str[100]={0};
for(int i=0;i<len;i++)
if(isdigit(ch[i]))
str[strlen(str)] = ch[i];
len = strlen(str);
int digit = 0;
for(int i=0;i<len;i++)
{
digit = digit*10;
digit += str[i]-'0';
if(digit>='0')
{
cout << (char)digit;
digit = 0;
}
}
}

获得flag

image.png

1
moectf{pyth0n_1s_s0_s1mple}

(python is so simple(指我用C++写题(x(wwwwww

Posted on

2020-11-13

Updated on

2020-11-18

Licensed under

Comments

:D 一言句子获取中...

Loading...Wait a Minute!