跳到正文

个人记录

【项目】代码混淆器

童年的小翼龙约 12 分钟
原文
文章信息与版本

文章信息

发布
2023年10月11日
收录
2025年12月12日
更新
2026年11月10日
篇幅
约 12 分钟
获赞
1

版本

  1. v1当前

代码混淆器,让你放心小号逃罚时


在打 CF 时,你有没有过拿小号交代码过了再用大号交以逃避罚时的想法?

又有没有过实践了上述想法导致 skip 一场比赛的经历?

如果有,那么你需要这款代码混淆器!

基于【项目】代码混淆器 by _sunkuangzheng_ 二次开发。

【功能介绍】

代码混淆器可以将你的变量名全部改成常见或随机字符串,同时添加一些随机注释,并保证代码还能正常运行。通过它,CF 将不能识别你的大小号代码是否雷同!

【使用说明】

测试环境为 Windows10, MinGW-GCC13。
请自行编译使用。

【已知 BUG】

目前对字符串的处理有问题,会将你输出的字符串替换为随机字符,预计 0.2 版本修复。 (已修复)

【版本号】

0.4

【更新日志】

0.1:最初版本
0.2:修复了会替换字符串的问题(大概
0.3:增加了一些 STL 关键字,降低了随机注释概率。
0.4:增加了一些 STL 关键字,感谢 NO21 的贡献。

【效果演示】

_sunkuangzheng_ 项目版本

本项目当前版本

【源代码】

请自行编译使用:

C++
#include <bits/stdc++.h>
using namespace std;
namespace Code_Maker{

vector<string> Key_Word{"auto","bool","char","int","short","long","float","double",
"signed","unsigned","false","true","enum","struct","class","namespace","std","using","priority_queue",
"cin","for","while","main","const","map","set","vector","pair","queue","stack","sync_with_stdio",
"priority","do","if","else","inline","register","void","operator","break","continue","return","tuple",
"scanf","printf","floor","ceil","size","top","front","pop","bitset","cin","cout","push","back","emplace",
"clear","endl","string","swap","define","min","max","rand","sort","ios","sync","with","stdio","tie","emplace_back", 
"sqrt","emplace","gcd","isdigit","getchar","first","second","memset","sizeof","begin","end","push_back",
"lower_bound","upper_bound","bound","unique","abs","lcm","__gcd","and","or","xor","typedef","iterator","puts","find","erase","make_pair"};
vector<string> Bianliang_Name{"answer","result","lengthh","sizee","father","depth","value","valve","csgo","cs2","counter_strike2",
"nic","tuoc","ftnirp","kcuf","deg","LycoReco","NishikigiChisato","InoueTakina","omen","luogu","kkksb03","shen_bhe","BianLiang",
"Waccepted","AcrongAnswer","baoling","IAKIOI","jc","spfa","tarjan","SPFA","dfs1","dfs2","dfs3","dfs4","dfs5","dfs6","dfs114514",
"bfs1","bfs2","bfs3","bfs1919810","read","write","calc","solve","work","vscode","vim","dev_c__","dinic","This_Is_A_Value",
"This_Is_Also_A_Value","IDontKnow","ChisatoLoveTakina","You_re_right","But","WHOFUCKED"};
vector<string> Zhushi_Name{"using dfs to get the Ans","I Love Coding","I want to AK IOI",
"I Don't Want to AK IOI","I Love Money","Codeforces is my favourite OJ","ATCoder is my favourite OJ",
"Luogu is my favourite OJ","Hydro is my favourite OJ","You're right. BUT WHO FUCKED?","Oh,My god.",
"No one could succeed without tears. So take aim of your target, just FUCK IT!",
"No one could shutdown my computer without exiting MSPaint first."};

mt19937 rd(time(nullptr));
ifstream fin;
ofstream fout;
map <string,string> mymap;
int bianliang_cnt , zhushi_cnt;
bool is_val(char c , bool flag)
{
    return ('a' <= c and 'z' >= c) or ('A' <= c and 'Z' >= c) or (flag and '0' <= c and '9' >= c) or (c == '_');
}
string get_next_word(string s , int &pos)
{
    string re = ""; int len = s.length() , now;
    for (now = pos; now < len;) {
        if (!is_val(s[now] , now>pos)){break;}
        re += s[now]; now++;
    }
    if (now == pos){re += s[now++];}
    pos = now;
    return re;
}
string rd_name()
{
    int len = rd() % 15 + 1;
    string s = "";
    for (int i = 0; i < len; i++){s += char(rd()%26+'a');}
    return s;
}
string rd_zhushi()
{
    int len = rd() % 15 + 15;
    string s = "";
    for (int i = 0; i < len; i++){s += char(rd()%26+'a');}
    return s;
}
string new_bianliang()
{
    if (++bianliang_cnt < Bianliang_Name.size()){return Bianliang_Name[bianliang_cnt];}
    else{return rd_name();}
}
string new_zhushi()
{
    if (++zhushi_cnt < Zhushi_Name.size()){return Zhushi_Name[zhushi_cnt];}
    else{return rd_zhushi();}
}
void try_output_zhushi()
{
    if (rd() % 50 == 0) {
        fout << "/\/" << new_zhushi() << '\n';
    }
}
void main()
{
    shuffle(Bianliang_Name.begin() , Bianliang_Name.end() , rd);
    shuffle(Zhushi_Name.begin() , Zhushi_Name.end() , rd);
    for (auto i : Key_Word){mymap[i] = i;}

    string in_file_name;
    cout << "Pls Enter the File Name of Your Code: ";
    cin >> in_file_name;
    cout << "In Processing. Pls Wait...\n";
    fin.open(in_file_name); fout.open("Code.cpp");

    string s;
    while(getline(fin , s)) {
        int cnt = 0;
        while(!s.empty() and s[0] == ' '){s.erase(0,1); cnt++;}
        if (s.empty()){continue;}

        int len = s.length();
        if (s[0] == '#') {
            int i = 1;
            if (get_next_word(s , i) != "define") {
                fout << s;
            } else {
                string ans = "#define";
                while(i < len) {
                    if (!is_val(s[i] , 0)){ans += s[i++];}
                    else {
                        string tmp = get_next_word(s , i);
                        if (!mymap.count(tmp)){mymap.insert({tmp , new_bianliang()});}
                        ans += mymap[tmp];
                    }
                } fout << ans;
            }
        } else {
            while(cnt--){fout << ' ';}
            int i = 0;
            string ans = "";
            while(i < len) {
                if (!is_val(s[i] , 0)) {
                    if ('0' <= s[i] and '9' >= s[i]) {
                        while(i < len and is_val(s[i] , 1)) {
                            ans += s[i++];
                        }
                    } else if (s[i] == '\"') {
                        ans += s[i++];
                        while(i < len and s[i] != '\"') {
                            ans += s[i++];
                        }
                        if (i < len){ans += s[i++];}
                    } else {
                        ans += s[i++];
                    }
                } else {
                    string tmp = get_next_word(s , i);
                    if (!mymap.count(tmp)){mymap.insert({tmp , new_bianliang()});}
                    ans += mymap[tmp];
                }
            } fout << ans;
        }

        try_output_zhushi();
        fout << '\n';
        try_output_zhushi();
    }
}

}int main(){Code_Maker :: main(); return 0;}
原文
存档评论4 条抓取于