版本比较
代码抽象器
正文
增加 16 行删除 564 行
4 行未改动56789910111213141511121617181920212223242526272812 行未改动41424344334546474849505152415343444554474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960055565758596066074 行未改动代码抽象器是由 C++ 研发的,一款用于将原本正常的 C++ 代码,利用 C++ 中的特殊语法,修改为令人难以读懂的全新代码。能有效混淆代码,起到保护代码的作用。
这一项目主张不改变代码的原本逻辑,在尽可能不影响代码的运行速度与占用内存的情况下最大程度混淆代码。目前有以下功能:
- 添加随机缩进、随机注释、随机反斜杠和转换中括号、大括号等。- 添加随机缩进。- 添加随机注释。- 添加随机反斜杠。- 将 `[]` 转换为 `<::>`。- 将 `{}` 转换为 `<%%>`。- 将 `#` 转换为 `%:`。- 将 `&&` 和 `||` 分别转换为 `and` 和 `or`。- 将 `&=` 转换为 `and_eq`、将 `|=` 转换为 `or_eq`、将 `^=` 转换为 `xor_eq`、将 `!=` 转换为 `not_eq`。- 将 `&` 转换为 `bitand`、将 `|` 转换为 `bitor`、将 `^` 转换为 `xor`、将 `!` 转换为 `not`、将 `~` 转换为 `compl`。- 将 `&=` 转换为 `and_eq`。- 将 `|=` 转换为 `or_eq`。- 将 `^=` 转换为 `xor_eq`。- 将 `!=` 转换为 `not_eq`。- 将 `&` 转换为 `bitand`。- 将 `|` 转换为 `bitor`。- 将 `^` 转换为 `xor`。- 将 `!` 转换为 `not`。- 将 `~` 转换为 `compl`。- 将 `while` 转为 `for`。- 将字符转为数字。- 删除空行与有概率删除换行。
12 行未改动测试一下代码是否正确。

可以看到代码能够保持与抽象前一样的功能。可以看到代码能够保持与抽象前一样的功能~~而且可读性极高~~。
## 三、下载
可执行程序:[代码抽象器.exe](https://www.luogu.com.cn/fe/api/problem/downloadAttachment/8wt7d7ca)。
同时也可以在本地编译源码得到可执行程序。
::::info[源码]
```cpp#include <bits/stdc++.h>#include <windows.h>
using namespace std;
map <string, bool> Define;string s, S;string monkeytype[250] = {"zdjd", "dijkstra", "log", "primal-dual", "edmonds-karp", "SPFA", "florr.io", "floor", "floyd", "dinic", "ff", "ffa", "generals.io", "segment", "tree", "tree", "beats", "DAG", "flow", "long long", "long long int", "FFT", "NTT", "Tarjan" , "double", "CPU", "GPU", "GPT", "deepseek", "deekseep", "AI GENERATED", "ds", "dsa", "dsa", "dsa", "PPT", "mine", "craft", "subtree", "subtask" , "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "ls", "rs", "l", "r", "mid", "pushup", "pushdown", ",merge", "modify", "query" , "build", "subtask n", "sigma", "ans", "sum", "+=", "*=", "-=", "/=", "^=", "&=", "bitset", "|=", "%=", "+", "-", "=", "*", "/", "%", "^", "&", "|", "}", "{", "]", "[", ".size", "function", "triangle", "love", "love", "float", "string", "substring", "subline", "kskbl", "TLE", "MLE", "RE", "WA", "WA+TLE", "TLE+MLE", "TrueGod", "SE", "PE", "line", "linux", "NOI", "NOIP", "CSP-J", "CSP-S", "CTS", "CTT", "IOI", "simulator", "114514", "1919819", "mul", "dist" , "a-z", "logn", "n^2", "n", "n/2", "dp", "johnson", "random", "rand", "rand()", "STL", "queue", "map", "unordered_map", "ST", "stack", "priority_queue", "deque", "mutable", "set", "games", "steam", "slay", "the", "a", "spire", "cat", "super auto pets", "driver", "florr.io", "generals.io", "zhihu.com", ".com", ".cn", ".wiki", ".top", ".org", ".ac", ".wa", "something", "KD-tree", "lazytag", "u", "u << 1", "u << 1 | 1", "fa", "n", "m", "s", "t", "x", "y", "max", "min", "mex", "wax", "bitwise", "xor", "or", "ans", "not", "cnt", "ak!!!", "ac", "akioi", "cout", "return", "-1", "cerr", "cin", "printf", "scanf", "ios_base", "sync", "tie", "bot", "team", "rank", "ranking", "rp", "rating", ">>", "<<", ";", ":", "(", "!", ")", "?", "_", "qwq", "<", ">", "struct", "node", "dep", ".", ".", ".", ".", ".", "++", "--", "==", "duel", "orz", "orz", "sto", "qp", "zc", "lol", "std", "main", "miao", "mian", "time(0)", "srand", "code", "True", "God", "tag", "OI", "OIER", "AFO", "point", "pts", "leaf", "value", "int"};mt19937 rd(chrono :: duration_cast <chrono :: nanoseconds> (chrono :: system_clock :: now().time_since_epoch()).count());int rd_int(int l, int r) { std :: uniform_int_distribution <int> dist(l, r); return dist(rd); }
string Random_Word() { return monkeytype[rd_int(0, 248)]; }string Random_String() { string res; for (int i = rd_int(1, 8); i >= 1; i--) res += Random_Word() + ' '; return res; }int Count_Backslash(string &s, int pos) { int res = 0; for (int i = pos - 1; i >= 0 and s[i] == '\\'; i--) res++; return res; }bool Check_Number(char c) { return (c >= '0' and c <= '9'); }bool Check_Letter(char c) { return ((c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z')); }bool Check_Underline(char c) { return (c == '_'); }bool Check_Key(char c) { return (Check_Number(c) or Check_Letter(c) or Check_Underline(c)); }bool Check_Legal(string &s, int pos) { return !(Count_Backslash(s, pos) & 1); }bool Check_End(string &s, int pos) { return (pos == s.size() - 1); }bool Check_Begin(string &s, int pos) { return (pos == 0); }bool Check_Define(string x) { return Define[x]; }void Erase_String(string &s, int l, int r) { if (l > r) return ; s.erase(l, r - l + 1); }/* 找 pos 之后的第一个双引号 */ int Find_Double_Quotation(string &s, int pos) { for (int i = pos + 1; i < s.size(); i++) { if (s[i] == '\"' and Check_Legal(s, i)) return i; } return pos;}/* 找 pos 之后的第一个单引号 */ int Find_Single_Quotation(string &s, int pos) { for (int i = pos + 1; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) return i; } return pos;}/* 找 pos 之后的第一个右括号 */ int Find_Right_Parentheses(string &s, int pos) { int cnt = 1; for (int i = pos + 1; i < s.size(); i++) { if (s[i] == '(') cnt++; if (s[i] == ')') cnt--; if (!cnt) return i; } return -1;}/* 找 pos 之后的第一个换行 */ int Find_Enter(string &s, int pos) { for (int i = pos + 1; i < s.size(); i++) { if (s[i] == '\n') return i; } return s.size();}/* 找 pos 之前的第一个换行 */ int Find_Last_Enter(string &s, int pos) { for (int i = pos - 1; i >= 0; i--) { if (s[i] == '\n') return i; } return -1;}/* 判断 pos 和 pos + 1 两个位置是否构成单行注释 */ bool Check_Single_Line_Note(string &s, int pos) { if (Check_End(s, pos) or s[pos] != '/' or s[pos + 1] != '/') return 0; return 1; }/* 判断 pos 和 pos + 1 两个位置是否构成多行注释 */ bool Check_Serval_Line_Note(string &s, int pos) { if (Check_End(s, pos) or s[pos] != '/' or s[pos + 1] != '*') return 0; return 1;}/* 找 pos 之后第一个多行注释的结束 */ int Find_Serval_Line_Note(string &s, int pos) { for (int i = pos + 1; i < s.size(); i++) { if (!Check_Begin(s, i) and s[i - 1] == '*' and s[i] == '/') return i; } return s.size() - 1;}/* 找 pos 之前第一个有意义字符的位置 */ int Find_Last_Char(string &s, int pos) { for (int i = pos - 1; i >= 0; i--) { if (s[i] != '\t' and s[i] != '\n' and s[i] != ' ') return i; } return -1;}/* 找 pos 之后第一个有意义字符的位置 */ int Find_Next_Char(string &s, int pos) { for (int i = pos + 1; i < s.size(); i++) { if (s[i] != '\t' and s[i] != '\n' and s[i] != ' ') return i; } return -1;}/* 截取 pos 之后的最长可能变量名 */ string Cut_String(string &s, int pos) { string res; for (int i = pos; i < s.size() and Check_Key(s[i]); i++) res += s[i]; return res;}/* 截取 l ~ r 的子串 */ string Cut_Substr(string &s, int l, int r) { if (l > r) return ""; return s.substr(l, r - l + 1); }/* 将数字转为字符串 */ string Number_To_String(int x) { string res; while (x) { res += (x % 10) + '0'; x /= 10; } reverse(res.begin(), res.end()); return res;}void erase_backslash(string &s) { for (int i = 0; i < s.size(); i++) { if (s[i] == '\n') { int p = Find_Last_Char(s, i); if (p != -1 and s[p] == '\\') { Erase_String(s, i, i), Erase_String(s, p, p); i -= 2; } } }}void erase_note(string &s) { for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (Check_Single_Line_Note(s, i)) { Erase_String(s, i, Find_Enter(s, i) - 1); s.insert(i, " "); } if (Check_Serval_Line_Note(s, i)) { Erase_String(s, i, Find_Serval_Line_Note(s, i + 2)); s.insert(i, " "); } }}void save_define(string &s) { if (s.size() >= 7) { for (int i = 0; i + 6 < s.size(); i++) { if (s.substr(i, 7) == "#define") { int pos = Find_Next_Char(s, i + 6); if (pos != -1) Define[Cut_String(s, pos)] = 1; } } }}void change_bracket(string &s) { for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (s[i] == '[' and rd_int(1, 10) <= 9) s.replace(i, 1, "<:"); if (s[i] == ']' and rd_int(1, 10) <= 9) s.replace(i, 1, ":>"); if (s[i] == '{' and rd_int(1, 10) <= 9) s.replace(i, 1, "<%"); if (s[i] == '}' and rd_int(1, 10) <= 9) s.replace(i, 1, "%>"); }}void change_hashsign(string &s) { for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (s[i] == '#') s.replace(i, 1, "%:"); }}void change_while(string &s) { if (Check_Define("for") or Check_Define("while")) return ; if (s.size() >= 5) { for (int i = 0; i + 4 < s.size(); i++) { if (s.substr(i, 5) == "while") { int p1 = Find_Last_Char(s, i), p2 = Find_Next_Char(s, i + 4); if ((p1 == -1 or !Check_Key(s[p1])) and p2 != -1 and s[p2] == '(') { int p3 = Find_Right_Parentheses(s, p2); if (p3 == -1) continue; string tmp = "for"; for (int i = rd_int(0, 2); i >= 1; i--) tmp += ' '; tmp += '('; for (int i = rd_int(0, 2); i >= 1; i--) tmp += ' '; tmp += ';'; for (int i = rd_int(0, 2); i >= 1; i--) tmp += ' '; tmp += Cut_Substr(s, p2 + 1, p3 - 1); for (int i = rd_int(0, 2); i >= 1; i--) tmp += ' '; tmp += ';'; for (int i = rd_int(0, 2); i >= 1; i--) tmp += ' '; tmp += ')'; Erase_String(s, i, p3); s.insert(i, tmp); } } } }}void change_and(string &s) { if (Check_Define("and")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and !Check_End(s, i) and s[i] == '&' and s[i + 1] == '&') { if (Check_Begin(s, i) and Check_End(s, i + 1)) s.replace(i, 2, "and"); else if (Check_Begin(s, i)) { if (s[i + 2] == ' ') s.replace(i, 2, "and"); else s.replace(i, 2, "and "); } else if (Check_End(s, i + 1)) { if (s[i - 1] == ' ') s.replace(i, 2, "and"); else s.replace(i, 2, " and"); } else { if (s[i - 1] == ' ' and s[i + 2] == ' ') s.replace(i, 2, "and"); else if (s[i - 1] == ' ') s.replace(i, 2, "and "); else if (s[i + 2] == ' ') s.replace(i, 2, " and"); else s.replace(i, 2, " and "); } } }}void change_or(string &s) { if (Check_Define("or")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and !Check_End(s, i) and s[i] == '|' and s[i + 1] == '|') { if (Check_Begin(s, i) and Check_End(s, i + 1)) s.replace(i, 2, "or"); else if (Check_Begin(s, i)) { if (s[i + 2] == ' ') s.replace(i, 2, "or"); else s.replace(i, 2, "or "); } else if (Check_End(s, i + 1)) { if (s[i - 1] == ' ') s.replace(i, 2, "or"); else s.replace(i, 2, " or"); } else { if (s[i - 1] == ' ' and s[i + 2] == ' ') s.replace(i, 2, "or"); else if (s[i - 1] == ' ') s.replace(i, 2, "or "); else if (s[i + 2] == ' ') s.replace(i, 2, " or"); else s.replace(i, 2, " or "); } } }}void change_xor(string &s) { if (Check_Define("xor")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and s[i] == '^' and (Check_End(s, i) or s[i + 1] != '=')) { if (Check_Begin(s, i) and Check_End(s, i)) s.replace(i, 1, "xor"); else if (Check_Begin(s, i)) { if (s[i + 1] == ' ') s.replace(i, 1, "xor"); else s.replace(i, 1, "xor "); } else if (Check_End(s, i)) { if (s[i - 1] == ' ') s.replace(i, 1, "xor"); else s.replace(i, 1, " xor"); } else { if (s[i - 1] == ' ' and s[i + 1] == ' ') s.replace(i, 1, "xor"); else if (s[i - 1] == ' ') s.replace(i, 1, "xor "); else if (s[i + 1] == ' ') s.replace(i, 1, " xor"); else s.replace(i, 1, " xor "); } } }}void change_not(string &s) { if (Check_Define("not")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and s[i] == '!' and (Check_End(s, i) or s[i + 1] != '=')) { if (Check_Begin(s, i) and Check_End(s, i)) s.replace(i, 1, "not"); else if (Check_Begin(s, i)) { if (s[i + 1] == ' ') s.replace(i, 1, "not"); else s.replace(i, 1, "not "); } else if (Check_End(s, i)) { if (s[i - 1] == ' ') s.replace(i, 1, "not"); else s.replace(i, 1, " not"); } else { if (s[i - 1] == ' ' and s[i + 1] == ' ') s.replace(i, 1, "not"); else if (s[i - 1] == ' ') s.replace(i, 1, "not "); else if (s[i + 1] == ' ') s.replace(i, 1, " not"); else s.replace(i, 1, " not "); } } }}void change_and_eq(string &s) { if (Check_Define("and_eq")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and !Check_End(s, i) and s[i] == '&' and s[i + 1] == '=') { if (Check_Begin(s, i) and Check_End(s, i + 1)) s.replace(i, 2, "and_eq"); else if (Check_Begin(s, i)) { if (s[i + 2] == ' ') s.replace(i, 2, "and_eq"); else s.replace(i, 2, "and_eq "); } else if (Check_End(s, i + 1)) { if (s[i - 1] == ' ') s.replace(i, 2, "and_eq"); else s.replace(i, 2, " and_eq"); } else { if (s[i - 1] == ' ' and s[i + 2] == ' ') s.replace(i, 2, "and_eq"); else if (s[i - 1] == ' ') s.replace(i, 2, "and_eq "); else if (s[i + 2] == ' ') s.replace(i, 2, " and_eq"); else s.replace(i, 2, " and_eq "); } } }}void change_or_eq(string &s) { if (Check_Define("or_eq")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and !Check_End(s, i) and s[i] == '|' and s[i + 1] == '=') { if (Check_Begin(s, i) and Check_End(s, i + 1)) s.replace(i, 2, "or_eq"); else if (Check_Begin(s, i)) { if (s[i + 2] == ' ') s.replace(i, 2, "or_eq"); else s.replace(i, 2, "or_eq "); } else if (Check_End(s, i + 1)) { if (s[i - 1] == ' ') s.replace(i, 2, "or_eq"); else s.replace(i, 2, " or_eq"); } else { if (s[i - 1] == ' ' and s[i + 2] == ' ') s.replace(i, 2, "or_eq"); else if (s[i - 1] == ' ') s.replace(i, 2, "or_eq "); else if (s[i + 2] == ' ') s.replace(i, 2, " or_eq"); else s.replace(i, 2, " or_eq "); } } }}void change_xor_eq(string &s) { if (Check_Define("xor_eq")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and !Check_End(s, i) and s[i] == '^' and s[i + 1] == '=') { if (Check_Begin(s, i) and Check_End(s, i + 1)) s.replace(i, 2, "xor_eq"); else if (Check_Begin(s, i)) { if (s[i + 2] == ' ') s.replace(i, 2, "xor_eq"); else s.replace(i, 2, "xor_eq "); } else if (Check_End(s, i + 1)) { if (s[i - 1] == ' ') s.replace(i, 2, "xor_eq"); else s.replace(i, 2, " xor_eq"); } else { if (s[i - 1] == ' ' and s[i + 2] == ' ') s.replace(i, 2, "xor_eq"); else if (s[i - 1] == ' ') s.replace(i, 2, "xor_eq "); else if (s[i + 2] == ' ') s.replace(i, 2, " xor_eq"); else s.replace(i, 2, " xor_eq "); } } }}void change_not_eq(string &s) { if (Check_Define("not_eq")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and !Check_End(s, i) and s[i] == '!' and s[i + 1] == '=') { if (Check_Begin(s, i) and Check_End(s, i + 1)) s.replace(i, 2, "not_eq"); else if (Check_Begin(s, i)) { if (s[i + 2] == ' ') s.replace(i, 2, "not_eq"); else s.replace(i, 2, "not_eq "); } else if (Check_End(s, i + 1)) { if (s[i - 1] == ' ') s.replace(i, 2, "not_eq"); else s.replace(i, 2, " not_eq"); } else { if (s[i - 1] == ' ' and s[i + 2] == ' ') s.replace(i, 2, "not_eq"); else if (s[i - 1] == ' ') s.replace(i, 2, "not_eq "); else if (s[i + 2] == ' ') s.replace(i, 2, " not_eq"); else s.replace(i, 2, " not_eq "); } } }}void change_compl(string &s) { if (Check_Define("compl")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and s[i] == '~') { if (Check_Begin(s, i) and Check_End(s, i)) s.replace(i, 1, "compl"); else if (Check_Begin(s, i)) { if (s[i + 1] == ' ') s.replace(i, 1, "compl"); else s.replace(i, 1, "compl "); } else if (Check_End(s, i)) { if (s[i - 1] == ' ') s.replace(i, 1, "compl"); else s.replace(i, 1, " compl"); } else { if (s[i - 1] == ' ' and s[i + 1] == ' ') s.replace(i, 1, "compl"); else if (s[i - 1] == ' ') s.replace(i, 1, "compl "); else if (s[i + 1] == ' ') s.replace(i, 1, " compl"); else s.replace(i, 1, " compl "); } } }}void change_bitand(string &s) { if (Check_Define("bitand")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and s[i] == '&' and (Check_End(s, i) or (s[i + 1] != '=' and s[i + 1] != '&')) and (Check_Begin(s, i) or s[i - 1] != '&')) { if (Check_Begin(s, i) and Check_End(s, i)) s.replace(i, 1, "bitand"); else if (Check_Begin(s, i)) { if (s[i + 1] == ' ') s.replace(i, 1, "bitand"); else s.replace(i, 1, "bitand "); } else if (Check_End(s, i)) { if (s[i - 1] == ' ') s.replace(i, 1, "bitand"); else s.replace(i, 1, " bitand"); } else { if (s[i - 1] == ' ' and s[i + 1] == ' ') s.replace(i, 1, "bitand"); else if (s[i - 1] == ' ') s.replace(i, 1, "bitand "); else if (s[i + 1] == ' ') s.replace(i, 1, " bitand"); else s.replace(i, 1, " bitand "); } } }}void change_bitor(string &s) { if (Check_Define("bitor")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (rd_int(1, 48) <= 38 and s[i] == '|' and (Check_End(s, i) or (s[i + 1] != '=' and s[i + 1] != '|')) and (Check_Begin(s, i) or s[i - 1] != '|')) { if (Check_Begin(s, i) and Check_End(s, i)) s.replace(i, 1, "bitor"); else if (Check_Begin(s, i)) { if (s[i + 1] == ' ') s.replace(i, 1, "bitor"); else s.replace(i, 1, "bitor "); } else if (Check_End(s, i)) { if (s[i - 1] == ' ') s.replace(i, 1, "bitor"); else s.replace(i, 1, " bitor"); } else { if (s[i - 1] == ' ' and s[i + 1] == ' ') s.replace(i, 1, "bitor"); else if (s[i - 1] == ' ') s.replace(i, 1, "bitor "); else if (s[i + 1] == ' ') s.replace(i, 1, " bitor"); else s.replace(i, 1, " bitor "); } } }}void change_char(string &s) { if (Check_Define("char")) return ; for (int i = 0; i < s.size(); i++) { if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (s[i] == '\'' and Check_Legal(s, i)) { int p = Find_Single_Quotation(s, i); if (p != i + 2 or rd_int(1, 48) <= 38) { i = p; continue; } char c = s[i + 1]; string tmp = "( (char ) (" + Number_To_String((int)(c)) + " ) )"; s.replace(i, 3, tmp); i += tmp.size(); continue; } }}void change_tab(string &s) { for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (s[i] == '\n') { int pos = i + 1, time = rd_int(0, 10); string tmp; for (; pos < s.size() and (s[pos] == ' ' or s[pos] == '\t'); pos++); Erase_String(s, i + 1, pos - 1); for (int i = 1; i <= time; i++) tmp += ' '; s.insert(i + 1, tmp); } }}void erase_empty_line(string &s) { for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (s[i] == '\n') { int p1 = Find_Next_Char(s, i), p2 = Find_Enter(s, i); if (p2 == s.size()) continue; if (p1 == -1 or p1 > p2) Erase_String(s, i + 1, p2), i--; } }}void erase_enter(string &s) { for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (s[i] == '\n' and rd_int(1, 48) <= 38) { int p1 = Find_Next_Char(s, i), p2 = Find_Next_Char(s, Find_Last_Enter(s, i)); if (p1 == -1 or p1 >= Find_Enter(s, i) or p2 == -1 or p2 >= Find_Enter(s, Find_Last_Enter(s, i))) continue; if (s[p1] != '#' and s[p1] != '%' and s[p2] != '#' and s[p2] != '%') Erase_String(s, i, i), i--; } }}void insert_note(string &s) { for (int i = 0; i < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (Check_Serval_Line_Note(s, i)) { i = Find_Serval_Line_Note(s, i); continue; } if (s[i] == ' ') { if (rd_int(1, 78) == 1) { string tmp = "/* " + Random_String() + " */"; s.insert(i + 1, tmp); i += tmp.size(); } } } for (int i = 0; i < s.size(); i++) { if (s[i] == '\n' and rd_int(1, 10) == 1) { string tmp = "// " + Random_String(); s.insert(i, tmp); i += tmp.size(); } }}void insert_backslash(string &s) { for (int i = 0; i + 1 < s.size(); i++) { if (s[i] == '\'' and Check_Legal(s, i)) { i = Find_Single_Quotation(s, i); continue; } if (s[i] == '\"' and Check_Legal(s, i)) { i = Find_Double_Quotation(s, i); continue; } if (Check_Serval_Line_Note(s, i)) { i = Find_Serval_Line_Note(s, i); continue; } if (i <= 50) { if (rd_int(1, 5) == 1) s.insert(i + 1, "\\\n"), i += 2; } else { if (rd_int(1, 78) == 1) s.insert(i + 1, "\\\n"), i += 2; } }}bool copy_to_clipboard(const string &s) { if (OpenClipboard(NULL)) { EmptyClipboard(); HGLOBAL clip_buffer = GlobalAlloc(GMEM_DDESHARE, s.size() + 1); char *buffer = (char *)(GlobalLock(clip_buffer)); strcpy(buffer, s.c_str()); SetClipboardData(CF_TEXT, clip_buffer); CloseClipboard(); return 1; } return 0;}
int main() { while (getline(cin, s)) S += s + '\n'; erase_backslash(S); erase_note(S); save_define(S); change_bracket(S); change_hashsign(S); change_while(S); change_and(S); change_or(S); change_xor(S); change_not(S); change_and_eq(S); change_or_eq(S); change_xor_eq(S); change_not_eq(S); change_compl(S); change_bitand(S); change_bitor(S); change_char(S); change_tab(S); erase_empty_line(S); erase_enter(S); insert_note(S); insert_backslash(S); if (copy_to_clipboard(S)) cout << "Copied successful. The code has been copied to the clipboard.\n" << flush; else { cout << "Copy failed. The code has been output to \"strange code.txt\", please search for the file in the current file path.\n" << flush; fstream out; out.open("strange code.txt", ios :: out); out << S << flush; } system("pause"); return 0;}```::::
## 四、尾声
本项目完全手写,没有借助 AI,所以制作过程不算容易,实现也较为粗糙。将来会继续完善和更新新的功能。
同时本项目也可能存在 bug,希望大家能够~~养成在提交代码前抽象一下代码的习惯方便反馈 bug~~多多对本项目提出建议(可以直接在评论区指出)。
fun fact:如果只保留抽象器中的 `erase_backslash(S);` 和 `erase_note(S);` 两行,那么它将会变为代码净化器。