经典C程序求解

eileilei 2009-09-14 11:53:13
Problem 1
Read Ken Thompson's article ...

char s[] = {
'\t',
'0',
'\n',
'}',
';",
'\n',
'\n',
'/',
'*',
'\n',
(213 lines deleted)
0
};

/* The string s is a
* representation of the body
* of this program from '0'
* to the end.
*/

main(){
int i;
printf("char\ts{ } = {\n");
for(i=0; s[i]; i++)
printf("\t%d,\n",s[i]);
printf("%s",s);
}
Compile and run this program. You will have to figure out what goes in the 213 deleted lines. If you want, you can leave the comment out of the string s and out of the program. Explain the output. By itself, this program does not pose any sort of security threat. Explain in your own words what this program has to do with Thompson's Trojan Horse attack.
...全文
143 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hoomey 2009-09-15
  • 打赏
  • 举报
回复
mark
brookmill 2009-09-15
  • 打赏
  • 举报
回复
找到那个'0'了,刚才看错行了。
不过还是没看明白木马是怎么回事
tianya0609 2009-09-15
  • 打赏
  • 举报
回复
up
brookmill 2009-09-15
  • 打赏
  • 举报
回复
没看懂。
printf("%s",s); 执行这句的时候,s[1]的'0'为什么没打出来呢?
brookmill 2009-09-15
  • 打赏
  • 举报
回复
看看这个:Ken Thompson的经典c程序
http://topic.csdn.net/t/20020116/19/482123.html
brookmill 2009-09-15
  • 打赏
  • 举报
回复
省略的那213行,大概就是把后面那段注释和main函数的每个字符依次写下来,每个字符一行
brookmill 2009-09-15
  • 打赏
  • 举报
回复
找到原文了,这是Ken Thompson获得图灵奖的演讲的一部分。
这段代码是一个例子,它可以产生具有自我复制能力的程序。
不过……还是没看懂

Figure 1 shows a self-reproducing program in the C
programming language. (The purist will note that the
program is not precisely a self-reproducing program,
but will produce a self-reproducing program.) This entry
is much too large to win a prize, but it demonstrates
the technique and has two important properties that I
need to complete my story: 1) This program can be
easily written by another program. 2) This program can
contain an arbitrary amount of excess baggage that will
be reproduced along with the main algorithm. In the
example, even the comment is reproduced.
eileilei 2009-09-15
  • 打赏
  • 举报
回复
printf("%s",s);什么意思????????

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧