感觉没什么太特殊的地方,都是把原本的代码拿过来用而已,所以就觉得这些东西,没什么意思。
上面的代码是我从文章中自己摘出来的,然后自己看了看文章的解决方案写出的代码。
第一题:
破解下面的程序:
random.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand((unsigned int)time(NULL));
int targetnum=rand();
int destnum;
printf("Please enter:\n");
scanf("%d",&destnum);
if(destnum==targetnum)
{
printf("OK\n");
}
else
{
printf("No\n");
}
return 0;
}
solve.c
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<stdint.h>
#include<string.h>
int main()
{
uint32_t rand_num;
srand((unsigned int)time(NULL)); //seed with current time
rand_num = rand();
//uint32_t ans;
printf("%d\n", rand_num);
}
执行结果:
$ ./solve | ./random
Please enter:
OK
第二题:
破解下面的程序:
random.c
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
srand((unsigned int)time(NULL));
int array[6];
array[0] = 0x79;
array[1] = 0x12c97f;
array[2] = 0x135f0f8;
array[3] = 0x74acbc6;
array[4]=0x56c614e;
array[5]=0xffffffe2;
int j = 0;
while (j < 6)
{
int randVal = rand();
array[(long)j] = array[(long)j] - ((randVal%10) + -1);
j = j + 1;
}
int targetNumber = 0;
int i = 0;
while (i < 6)
{
targetNumber = targetNumber + array[(long)i];
i = i + 1;
}
int destnum;
scanf("%d",&destnum);
if(targetNumber==destnum)
{
printf("OK\n");
}
else
{
printf("NO\n");
}
//printf("targetNumber=%d\n",targetNumber);
//printf("destnum=%d\n",destnum);
return 0;
}
solve.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand((unsigned int)time(NULL));
int array[6];
array[0] = 0x79;
array[1] = 0x12c97f;
array[2] = 0x135f0f8;
array[3] = 0x74acbc6;
array[4]=0x56c614e;
array[5]=0xffffffe2;
int j = 0;
while (j < 6)
{
int randVal = rand();
array[(long)j] = array[(long)j] - ((randVal % 10) + -1);
j = j + 1;
}
int targetNumber = 0;
int i = 0;
while (i < 6)
{
targetNumber = targetNumber + array[(long)i];
i = i + 1;
}
printf("%d\n",targetNumber);
}
第三题:
破解下面的程序:
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
int main()
{
char target [504];
char input [512];
srand((unsigned int)time(NULL));
int i = 0;
while (i < 50)
{
int randVal = rand();
printf("%d days without an incident.\n",i);
sprintf(target,"%d",(randVal % 100));
scanf(" %10s",input);
strtok(input,"\n");
int check = strcmp(target,input);
if (check != 0)
{
puts("Well that didn\'t take long.");
printf("You should have used %s.\n",target);
exit(0);
}
i = i + 1;
}
puts("Success");
return 0;
}
solve.c
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
int main()
{
char target [504];
char input [512];
srand((unsigned int)time(NULL));
int i = 0;
while (i < 50)
{
int randVal = rand();
sprintf(target,"%d",(randVal % 100));
strtok(input,"\n");
printf("%s\n",target);
i++;
}
}