下载附件后发现是c文件,先分析一下。
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) { //没啥用,最后的hash计算用不到这个
if (argc != 4) {
printf("what?\n");
exit(1);
}
unsigned int first = atoi(argv[1]);
if (first != 0xcafe) { //当first不等于0xcafe时,提示错误
printf("you are wrong, sorry.\n");
exit(2);
}
//first=0xcafe
unsigned int second = atoi(argv[2]);
if (second % 5 == 3 || second % 17 != 8) { //当second被5取余=3和被17取余不=8时,提示错误
printf("ha, you won't get it!\n");
exit(3);
}
//second=25
if (strcmp("h4cky0u", argv[3])) { //strcmp()会比较h4cky0u和argv[3]是否相同,即当argv[3]不为h4cky0u时,提示错误
printf("so close, dude!\n");
exit(4);
}1
//
printf("Brr wrrr grr\n");
unsigned int hash = first * 31337 + (second % 17) * 11 + strlen(argv[3]) - 1615810207; //计算出hash
printf("Get your key: ");
printf("%x\n", hash); //%x的意思是转换为16进制
return 0;
}
运行c语言代码
把上面乱七八糟的全删了,直接将正确的参数代入就好
#include <stdio.h>
#include <string.h>
int main() {
unsigned int hash = 0xcafe * 31337 + (25 % 17) * 11 + strlen("h4cky0u") - 1615810207;
printf("Get your key: ");
printf("%x\n", hash);
return 0;
}
得到
Get your key: c0ffee
python
转换为python
hash = 0xcafe * 31337 + (25 % 17) * 11 + len("h4cky0u") - 1615810207
#strlen()函数在c里面是计算字符串长度的函数,对应python里的len()
print(hex(hash)) #得到的结果里前面会有0x,那个是16进制的标志,不是答案的一部分,无视即可