求1988年国际C语言乱码大赛获奖程序分析,作者是Ian Phillipps
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了求1988年国际C语言乱码大赛获奖程序分析,作者是Ian Phillipps相关的知识,希望对你有一定的参考价值。
#include <stdio.h>
main(t,_,a)char *a;
return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#\
;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l \
q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;#
\
)nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' \
iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c \
;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')#
\
'+##(!!/")
:t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
:0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
"!ek;dc i@bK'(q)-[w]*%n+r3#l,:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);
不加修改的在Visual Studio 2010中调试,虽然代码下有红线,但运行正常,能看到用英文写的文章,求程序分析。
// 编译环境main入口,CRTO.C for main(__argc, __argv, _environ);
// 方法的编译原来,返回值的寄存器状态
// 变量的类型转换reinterpret_cast
// 使用一个新的main方法,将旧的用一个新方法'decode'表示
// 根据题设,本程序执行方式为无命令参数,即,argc==1
// 变量的声名规约,改变变量名以方便理解
// 进一步重构if语句
#include <stdio.h>
int decode(int arg1,int arg2,char* sCodec)
if(1<arg1)
if(arg1<3)
decode(-79,-13,sCodec+decode(-87,1-arg2,decode(-86,0,sCodec+1)+sCodec));
if(arg1<arg2)
decode(arg1+1,arg2,sCodec);
if(decode(-94,-27+arg1,sCodec)&&arg1==2)
// 内部递归,无后续分支,可展平为递推方式
if(arg2<13)
return decode(2,arg2+1,"%s %d %d\n");
else
return 9;
else
return 16;
else if(arg1<-72)
// 可根据arg1范围代入。本条件代入后略
return decode(arg2,arg1,"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;# )nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c ;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')# '+##(!!/");
else if(arg1<-50)
// 内部递归,无后续分支,可展平为递推方式
if(arg2==*sCodec)
return putchar(sCodec[31]);
else
return decode(-65,arg2,sCodec+1);
else if(arg1<0)
// 内部递归,无后续分支,可展平为递推方式
return decode((*sCodec=='/')+arg1,arg2,sCodec+1);
else if(0<arg1) // arg1 == 1,初始情况,根据arg1取值取舍
return decode(2,2,"%s");
else // arg1 == 0
if(!(*sCodec=='/'))
// 内部递归,无后续分支,可展平为递推方式
return decode(0,decode(-61,*sCodec,"!ek;dc i@bK'(q)-[w]*%n+r3#l,:\nuwloca-O;m .vpbks,fxntdCeghiry"),sCodec+1);
else
return 1;
int main(int argc, char* argv[], char** _environ)
return decode(argc,(int)argv,(char*)_environ);
// 分析出递归顶层返回值。
// 注意所有return的含义,9/16/1/putchar(),Non Zero -> TRUE
// 分析arg1的内容,重构方法,有些坳,自己试着理解吧
#include <stdio.h>
int decode(int arg1,int arg2,char* sCodec)
if(1<arg1)
if(arg1<3)
decode(0,-86,"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;# )nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c ;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')# '+##(!!/");
decode(1-arg2,-87,"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;# )nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c ;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')# '+##(!!/");
decode(-13,-79,"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;# )nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c ;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')# '+##(!!/");
if(arg1<arg2)
decode(arg1+1,arg2,sCodec);
decode(-27+arg1,-94,"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;# )nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c ;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')# '+##(!!/");
if(arg1==2)
while(arg2<13)
arg2 ++;
sCodec = "%s %d %d\n";
// 上方条件代入
if(arg1<3)
decode(0,-86,"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;# )nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c ;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')# '+##(!!/");
decode(1-arg2,-87,"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;# )nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c ;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')# '+##(!!/");
decode(-13,-79,"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;# )nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c ;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')# '+##(!!/");
if(arg1<arg2)
decode(arg1+1,arg2,sCodec);
decode(-27+arg1,-94,"@n'+,#'/*w+/w#cdnr/+,r/*de+,/**+,/w%+,/w#q#n+,/#l+,/nn+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,w+K w'K:'+e#';dq#'l q#'+d'K#!/+k#;q#'reKK#w'reKKnl]'/#;#q#n'))#w'))nl]'/+#n';drw' i;# )nl]!/nn#'; r#w'r ncnl]'/#l,+'K rw' iK;[nl]'/w#q#n'wk nw' iwkKKnl]!/w%'l##w#' i; :nl]'/*q#'ld;r'nlwb!/*de'c ;;nl'-rw]'/+,##'*#nc,',#nw]'/+kd'+e+;#'rdq#w! nr'/ ') +rl#'n' ')# '+##(!!/");
else if(arg1<-50)
// 判断条件可达,取舍
char* s = sCodec;
while(!(arg2==*s))
s ++;
putchar(s[31]);
else if(arg1<0)
for(;arg1<0;arg1+=(*sCodec=='/'))
sCodec ++;
decode(0,arg2,sCodec+1); // 条件合并
else if(arg1 == 0)
while(!(*sCodec=='/'))
// 条件合并
decode(-61,*sCodec,"!ek;dc i@bK'(q)-[w]*%n+r3#l,:\nuwloca-O;m .vpbks,fxntdCeghiry");
sCodec ++;
return 1; // return TRUE only
int main(int argc, char* argv[], char** _environ)
decode(2,2,"%s");
return 9;
参考资料:http://webcache.googleusercontent.com/
参考技术A 就是递归调用啊!你找到第一个int main()开始向下分析。追问我也知道是递归和If嵌套,能说的详细点吗?
参考技术B 我在vc6.0下跑不出来,有错以上是关于求1988年国际C语言乱码大赛获奖程序分析,作者是Ian Phillipps的主要内容,如果未能解决你的问题,请参考以下文章