本文最后更新于412 天前,其中的信息可能已经过时,如有错误可以直接在文章下留言
BUUCTF里面的Misc题目,每天一道Misc题目娱乐一下,打开题目给的压缩包有一个ComeOn!.txt文件,打开来是很多个base编码,有很多等号,按照题目的标题应该是base64
直接全部复制放进Cyberchef里面解码,一次base64解码之后还是base编码的样子
那就再base64解码一次之后,得到了一段估计是C++代码,没学过C++,但看着不像是C
完整代码如下
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#define maxn 999
using nanespace std;
char$ca[maxn], cb[maxn];
int cmp(string a, string h©
{
Èif(k®size() > b.size())
) ".return 1;
else if(a.size() < b.size())
return -1;
else
{
for(int i = 0; i < a.size(); i++)
. &û
` $ if(a[i] < b[i])
& !À & return&.1;
` $ if(a[i] >`b[i])
(.........É.ÑÕɸ±;
}
+ #.return 0;
}
}
void reseta(string a)
{
`memset(ca,0,sizeof(ca));
.for(int i = 0; i < a.size(.; i++)
{
ca[i] = a[a.size()-1-i] - '0';
}
}
void resetb(string b)
{
`memset(cb,0,sizeof(cb));
for(int i = 0; i < b.size(); i++)
{
` $cb[©] = f[b.size().1-i] - '0';
` $//printf("%d",cb[i]);
}
}
string edd(string a, string b)//å. æ³.
{
reseta(a);//æ..æ¯.ä¸.ä½.å..ç..å..符å..æ..æ.°å..,并ä¸.æ..æ.°ç».å..è¿.æ.¥ä¾¿äº.å..é.¢ä¸.å..ä½.æ.°ç.¸å.
resetb(b);
for(int i#= 0; i <#maxn; i++)
{
ca[i] = ca[i] + cb[i];
if(ca[i] >= 2){
# à ca[i+1] +=#1;
ca[i] -= 2;
}
}
bool flag = true;
Èstring c = "";
for(int i = maxn - 1; i >= 0; i--)
{
if(flag && ca[i] == 0)
continue;
if(ca[i] != 0)
* "À flag = false;
. &ã += (ca[i] + '0');
//printf("%d",ca[i]);
}
if(flag)
` $return "0";
else
+ #.return c;
}
string minu(string a, string b)//å..æ³.
{
int sign = 0;
if(cmp(a, b) == -1)//aä¸.åº.该å..è¾.大ç..é.£ä¸ªæ.°
{
sign = 1;
string temp = a;
a = b;
b = temp;
}
reseta(a);
resetb(b);
for(int i = 0; i < maxn; i++)
{
if(ca[i] < cb[i]){
ca[i+1] -= 1;
ca[i] += 2;
}
ca[i] = ca[i] - cb[i];
}
bool flag = true;
string d = "";
for(int i = maxn - 1; i >= 0; i--)
{
if(flag && ca[i] == 0)
continue;
if(ca[i] != 0)
flag = false;
d += (ca[i] + '0');
//printf("%d",ca[i]);
}
if(flag)
return "0";
else
return d;
}
string mul(string x, string y)//s为符å.·ä½.
{
int lenx = x.size();
int leny = y.size();
if(lenx == 1)
{
//cout<<x<<" "<<y<<endl;
if(x == "1" && y == "1")
return "1";
else
return "0" ;
}
//printf("%d--%d\n",lenx,leny);
string a, b, c,d;
a = x.substr(0, lenx/2);
b = x.substr(lenx/2, lenx/2);
c = y.substr(0, leny/2);
d = y.substr(leny/2, leny/2);
printf("%d--%d--%d--%d--------------------------------------------%d-%d\n",a.size(), b.size(), c.size(), d.size(), x.size(), y.size());
//cout<<x<<":"<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
string ac = mul(a, c);
string bd = mul(b, d);
//cout<<x<<":"<<ac<<" "<<bd<<endl;
string ab = minu(a, b);//a-b
string cd = minu(d, c);
//cout<<x<<":"<<ab<<" "<<cd<<endl;
string abcd = mul(ab, cd);
//cout<<x<<":"<<abcd<<endl;
string first = ac;
for(int i = 0; i < (lenx); i++)
first += "0";
//cout<<ac<<" -----ac---- "<<first<<endl;
string second = add(abcd, ac);
second = add(second, bd);
for(int i = 0; i < (lenx/2); i++)
second += "0";
string fin = add(first, second);
return add(fin, bd);
}
int main(void)
{
string x, y;
printf("请è¾.å.¥ä¸¤ä¸ªäº.è¿.å.¶æ.°å..: ");
cin>>x>>y;
string ans = mul(x, y);
cout<<ans;
}
但是代码里面好像又该死的有些乱码,比如最后的这个printf(“请è¾.å.¥ä¸¤ä¸ªäº.è¿.å.¶æ.°å..: “); 现在看到乱码就害怕,我的思路的话就感觉这有点像Reverse的倒推,写脚本倒推得出flag,毕竟这段C++代码里确实出现了flag。奈何小白不会C++,直接看Writeup