1#include <stdio.h>
2#include <string.h>
3int main(int argc, char *argv[]) {
4 if (argc != 4) { // argc = 4
5 printf("what?\n");
6 exit(1);
7 }
8 unsigned int first = atoi(argv[1]);
9 if (first != 0xcafe) { // first = 0xcafe
10 printf("you are wrong, sorry.\n");
11 exit(2);
12 }
13 unsigned int second = atoi(argv[2]);
14 if (second % 5 == 3 || second % 17 != 8) {
15 printf("ha, you won't get it!\n");
16exit(3);
17// second = 25
18 }
19if (strcmp("h4cky0u", argv[3])) {
20printf("so close, dude!\n");
21 exit(4);
22// argv[3] = h4cky0u
23}
24 printf("Brr wrrr grr\n");
25unsigned int hash = first * 31337 + (second % 17) * 11 + strlen(argv[3]) - 1615810207;
26printf("Get your key: ");
27printf("%x\n", hash);
28return 0;
29}
解题思路:
不难看出这属于一道代码分析题,我们需要计算的是第25行,由第27行知道结果需要以16位进制输出,而计算25行需要的就是利用argv[1—3]的数据计算。
if (argc != 4) { // argc = 4 printf("what?\n"); exit(1);} 为了需要程序的进行,argc!=4代表我们需要输入4,如若非4 则从符号“!”知道程序就会直接输出"what?\n"
unsigned int first = atoi(argv[1]; if (first != 0xcafe) { // first = 0xcafe
printf("you are wrong, sorry.\n"); exit(2); first != 0xcafe代表我们需要输入0xcafe,如若非0xcafe 则从符号“!”知道程序就会直接输出"you are wrong, sorry.\n" 所以first = 0xcafe
unsigned int second = atoi(argv[2]); if (second % 5 == 3 || second % 17 != 8) {
printf("ha, you won't get it!\n"); exit(3); “||”逻辑或,两边同时为假则整体为假,这时候我想到一个数--25 所以second=25
(strcmp("h4cky0u", argv[3])) {printf("so close, dude!\n"); exit(4); 最后,看strcmp(“h4cky0u”, argv[3]),这个函数是用来判断是否相等的 相等strcmp返回0,退出if条件,那argv[3]=“h4cky0u”,strlen()函数用来计算字符串的长度,所以需要数字符串的长度,长度为7.
综上所述,运行程序就可以得到答案