Exercise 1 of SSD 6 -- C/C++
难得见到iCarnegie课程里的Exercise有如此生动的描述,居然还有007!汗……
C/C++一直是我的薄弱环节,这次多亏有高人相助~
现在看来这个题出得实在是奥妙无穷,佩服老外!!搞了我2个礼拜茶不思饭不香,终于理解其中的意思了。唉~ 谁让自己是转专业的,C++连课都没听过,内存分配也什么都不懂。不过这次是个开头,以后的题目应该慢慢适应吧,总不会每次都让别人手把手教我的。
[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
用到的文件:
secret.cpp
提交的报告:
引用:
The secret message.
From: CTE
To: You
Excellent!You got everything!
The secret keys.
3 777 -1 45
One paragraph describing, in your own prose, what process_keys12 does. For example, you might say that it modifies a specific program variable.
The function process_keys12 modifies the value of dummy. And then let dummy modifies the value of start and stride.
The meaning of the first two keys in terms of variables and addresses in the decoder program. For example, you might describe key2 by saying that its X-Y bits contain the value to which variable start is set. Or you might describe key1 by saying, for example, that it must be set equal to the number of memory addresses separating the address of two specific variables. These are only examples.
The function process_keys12 is used to modify the value of dummy. So from *(key1 + *key1) = *key2; in the decoder program, we can know that *(key1 + *key1) is the address of dummy and *key2 is the value. Then we can get key1 and key2.
One paragraph describing, in your own prose, what process_keys34 does.
The function process_keys34 modifies the address to which this function returns. Because the function must jump over the sentence: msg1 = extract_message1(start, stride); for containing the value of msg1[0] \0.
One paragraph describing the line of source code that is executed when the first call to process_keys34 returns.
The line of source code msg2 = extract_message2(start, stride); is executed when the first call to process_keys34 returns.
The meaning of the third and fourth keys in terms of variables and addresses in the decoder program.
The function process_keys34 is used to modify the address to which this function returns. So from *(((int *)&key3) + *key3) += *key4;, we can know that *(((int *)&key3) + *key3) is the address in which there is the address this function will returns. *key4 is the times of length of integer the function will jump over.
作业反馈:
引用:
The Description of process_keys12
Score: 10/12
sets the value of start and stride based on the first and second bytes of the value of dummy.
The Meaning of Key1
Score: 5/12
key1 is the offset of dummy's location from key1's location.
The Meaning of Key3
Score: 3/7
key3 is the offset between between key3's location and the return address in process_keys34.
The Meaning of Key4
Score: 2/7
key4 is the distance between the return address of the second invocation of process_keys34 and the first invocation of process_keys34.