-
-
[分享]CTF2019第六题解题过程
-
发表于: 2019-6-10 19:59 2611
-
考的是base64编码。修改网上的源码如下:
#include <iostream>
std::string value("tuvwxTUlmnopqrs7YZabcdefghij8yz0123456VWXkABCDEFGHIJKLMNOPQRS9+/");
std::string deciToBin_6bit(int deci) //10进制转2进制函数
{
std::string hexStr(6, ' ');
int Value = 0;
int i = 0;
for (; deci != 0; ++i, deci /= 2)
{
Value = deci % 2;
hexStr.at(i) = Value + '0';
}
hexStr = hexStr.substr(0, i);
reverse(hexStr.begin(), hexStr.end());
if (hexStr.length() < 6)
{
std::string add(6 - hexStr.length(), '0');
hexStr = add + hexStr;
}
return hexStr;
}
std:: string base64_decryption(const std::string in)
{
std::string out0;
std::string out1;
//std::string deciToBin_6bit(int);
for (auto x = in.cbegin(); (*x) != '=' && x != in.cend(); ++x) //排除等号
out0 += deciToBin_6bit(value.find(*x));
const int n = out0.length();
for (int i = 0; i < n; i += 8) //每8位提取一次
{
std::string subs = out0.substr(i, 8); //提取8位
int j = 0;
int sum = 0;
for (auto& x : subs)
{
sum += (x - '0') * pow(2, 7 - j);
++j;
} //按权展开,得到ASCII码
out1 += static_cast<char>(sum); //转换为相应字符
}
return out1;
}
char __cdecl charDecrypt(int data)
{
if ((0x9B - data) > 0x40 && (0x9B - data) <= 0x5a)
return 0x9B - data;
if ((data+0x40 )> 0x60 && (data+64) <= 0x7A)
return data+ 0x40;
if ((data-0x32) > 0x2F && (data-0x32) <= 0x39)
return data-0x32;
if (data == 0x77)
return 0x2B;
if (data == 0x79)
data = 0x2F;
return data;
}
char __cdecl charEncrypt(int data)
{
int dataa; // [esp+18h] [ebp+8h]
dataa = value[data];
if (dataa > 0x40 && dataa <= 0x5A)
return 0x9B - dataa;
if (dataa > 0x60 && dataa <= 0x7A)
return dataa - 64;
if (dataa > 0x2F && dataa <= 0x39)
return dataa + 0x32;
if (dataa == 0x2B)
return 0x77;
if (dataa == 0x2F)
dataa = 0x79;
return dataa;
}
int main()
{
std::string in = "!NGV%,$h1f4S3%2P(hkQ94==";
std::string out2;
for (auto x = in.cbegin(); (*x) != '=' && x != in.cend(); ++x) //排除等号
out2 += charDecrypt(*x);
out2 += "==";
std::cout << "hello";
std::cout << base64_decryption(out2);
return 0;
}
#include <iostream>
std::string value("tuvwxTUlmnopqrs7YZabcdefghij8yz0123456VWXkABCDEFGHIJKLMNOPQRS9+/");
std::string deciToBin_6bit(int deci) //10进制转2进制函数
{
std::string hexStr(6, ' ');
int Value = 0;
int i = 0;
for (; deci != 0; ++i, deci /= 2)
{
Value = deci % 2;
hexStr.at(i) = Value + '0';
}
hexStr = hexStr.substr(0, i);
reverse(hexStr.begin(), hexStr.end());
if (hexStr.length() < 6)
{
std::string add(6 - hexStr.length(), '0');
hexStr = add + hexStr;
}
return hexStr;
}
std:: string base64_decryption(const std::string in)
{
std::string out0;
std::string out1;
//std::string deciToBin_6bit(int);
for (auto x = in.cbegin(); (*x) != '=' && x != in.cend(); ++x) //排除等号
out0 += deciToBin_6bit(value.find(*x));
const int n = out0.length();
for (int i = 0; i < n; i += 8) //每8位提取一次
{
std::string subs = out0.substr(i, 8); //提取8位
int j = 0;
int sum = 0;
for (auto& x : subs)
{
sum += (x - '0') * pow(2, 7 - j);
++j;
} //按权展开,得到ASCII码
out1 += static_cast<char>(sum); //转换为相应字符
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)
赞赏
他的文章
- [分享]CTF2019总决赛第一题签到题 1963
- [分享]ctf2019第二轮第一题 1887
- [分享]CTF2019第六题解题过程 2612
看原图
赞赏
雪币:
留言: