编码-解码
编码图片
#include<bits/stdc++.h>
using namespace std;
int main(){
system("certutil -encode 1.png temp.txt");
system("start .\\temp.txt");
return 0;
}
编码
#include <string>
#include <vector>
#include <iostream>
using namespace std;
const string BASE64_CHARS =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
string base64_encode(const string &input) {
string encoded;
int val = 0, valb = -6;
const unsigned char* bytes = (const unsigned char*)input.c_str();
for (size_t i = 0; i < input.size(); ++i) {
val = (val << 8) + bytes[i];
valb += 8;
while (valb >= 0) {
encoded.push_back(BASE64_CHARS[(val >> valb) & 0x3F]);
valb -= 6;
}
}
if (valb > -6) {
encoded.push_back(BASE64_CHARS[((val << 8) >> (valb + 8)) & 0x3F]);
}
while (encoded.size() % 4) {
encoded.push_back('=');
}
// 去除最后的两个等号
if (encoded.size() >= 2 && encoded[encoded.size() - 1] == '=' && encoded[encoded.size() - 2] == '=') {
encoded.resize(encoded.size() - 2);
}
return encoded;
}
string base64_decode(const string &input) {
vector<int> decode_map(256, -1);
for (int i = 0; i < 64; ++i) {
decode_map[BASE64_CHARS[i]] = i;
}
string decoded;
int val = 0, valb = -8;
for (unsigned char c : input) {
if (decode_map[c] == -1) break;
val = (val << 6) + decode_map[c];
valb += 6;
if (valb >= 0) {
decoded.push_back(char((val >> valb) & 0xFF));
valb -= 8;
}
}
return decoded;
}
int main() {
string s;
freopen("base64.txt", "w", stdout);
cin >> s;
cout << base64_encode(s);
fclose(stdout);
system("start .\\base64.txt");
}
解码
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
const string BASE64_CHARS =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
string base64_decode(const string &input) {
vector<int> decode_map(256, -1);
for (int i = 0; i < 64; ++i) {
decode_map[BASE64_CHARS[i]] = i;
}
string decoded;
int val = 0, valb = -8;
for (unsigned char c : input) {
if (decode_map[c] == -1) break;
val = (val << 6) + decode_map[c];
valb += 6;
if (valb >= 0) {
decoded.push_back(char((val >> valb) & 0xFF));
valb -= 8;
}
}
return decoded;
}
string id(int n){
string s="";
for(int i=0;i<n;i++){
if(rand()%10>=5){
s+=(char)(rand()%10+'0');
}else{
if((rand()%10)>=5){
s+=(char)(rand()%26+'a');
}else{
s+=(char)(rand()%26+'A');
}
}
}
return s;
}
int main(){
srand(time(0));
string id_a=id(10);
system("cls");
system("color 0B");
cout << "嘿嘿嘿" << endl;
cout << "dev by zcygod" << endl;
cout << "id:" << id_a << endl;
cout << "这是你的id,请你把它给zcygod,zcygod会帮你生成一个key(每次重启程序key都会刷新)" << endl;
string key;
cout << "输入key:"<< endl ;
cin >> key;
key+="==";
string temp=base64_decode(key);
if(id_a==temp){
cout << "验证成功"<<endl;
}else{
cout << "验证失败.." << endl;
system("pause");
return 0;
}
cout << "请确保当前目录下有temp.txt!" << endl;
system("pause");
system("cls");
system("certutil -decode temp.txt 1.png");
system("start .\\1.png");
system("cls");
Sleep(3000);
system("erase /q 1.png");
system("erase /q temp.txt");
system("cls");
system("pause");
return 0;
}