本文以尋找質數程式為例,展示如何透過六個步驟將清晰易讀的 C 程式碼逐步轉化為極難理解的「混淆碼」。僅供娛樂與教學參考,嚴禁用於生產專案。
void primes(int cap) {
int i, j, composite;
for (i = 2; i < cap; ++i) {
composite = 0;
for (j = 2; j * j < i; ++j) {
composite += !(i % j);
}
if (!composite) printf("%d\t", i);
}
}
int main() { primes(100); }
void primes(int cap) {
int i, j, composite, t = 0;
while (t < cap * cap) {
i = t / cap;
j = t++ % cap;
if (i <= 1);
else if (!j) composite = j;
else if (j == i && !composite) printf("%d\t", i);
else if (j > 1 && j < i) composite += !(i % j);
}
}
void primes(int cap, int t, int composite) {
int i = t / cap, j = t % cap;
if (i <= 1) primes(cap, t+1, composite);
else if (!j) primes(cap, t+1, j);
else if (j == i && !composite) (printf("%d\t", i), primes(cap, t+1, composite));
else if (j > 1 && j < i) primes(cap, t+1, composite + !(i % j));
else if (t < cap * cap) primes(cap, t+1, composite);
}
int main() { primes(100, 0, 0); }
void primes(int m, int t, int c) {
int i = t / m, j = t % m;
(i <= 1) ? primes(m, t+1, c)
: (!j) ? primes(m, t+1, j)
: (j == i && !c) ? (printf("%d\t", i), primes(m, t+1, c))
: (j > 1 && j < i) ? primes(m, t+1, c + !(i % j))
: (t < m * m) ? primes(m, t+1, c) : 0;
}
void primes(int m, int t, int c) {
((t/m) <= 1) ? primes(m, t+1, c)
: !(t%m) ? primes(m, t+1, t%m)
: ((t%m)==(t/m) && !c) ? (printf("%d\t", t/m), primes(m, t+1, c))
: ((t%m)>1 && (t%m)<(t/m)) ? primes(m, t+1, c + !((t/m)%(t%m)))
: (t < m*m) ? primes(m, t+1, c) : 0;
}
void _(int __, int ___, int ____) {
((___/__)<=1) ? _(__,___+1,____)
: !(___%) ? _(__,___+1,___%__)
: ((___%)==(___/__)&&!____) ? (printf("%d\t",___/__),_(__,___+1,____))
: ((___%)>1&&(___%)<(___/__)) ? _(__,___+1,____+!((___/__)%(___%__)))
: (___<__*__) ? _(__,___+1,____) : 0;
}
int main() { _(100,0,0); }
void _(int __, int ___, int ____, int _____) {
((___/__)<=_____) ? _(__,___+_____,____,_____)
: !(___%) ? _(__,___+_____,___%__,_____)
: ((___%)==(___/__)&&!____) ? (printf("%d\t",___/__),_(__,___+_____,____,_____))
: ((___%)>_____&&(___%)<(___/__)) ? _(__,___+_____,____,_____+!((___/__)%(___%__)))
: (___<__*__) ? _(__,___+_____,____,_____) : 0;
}
int main() { _(100,0,0,1); }