-
Notifications
You must be signed in to change notification settings - Fork 1
/
hacker_think.c
71 lines (62 loc) · 1.46 KB
/
hacker_think.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <string.h>
#define MIN_N 100
#define MAX_N 1000
#define MIN_CHAR_SET_CHAR 'A'
#define MAX_PWD_LEN ((MAX_N)/(MIN_CHAR_SET_CHAR))
typedef struct s_
{
int N;
char *char_set;
char buf[MAX_PWD_LEN + 1];
int pos, cur_sum;
}think_state;
void think(think_state *state);
void think(think_state *state)
{
int i, sum;
for (i = 0; state->char_set[i] != '\0'; i++)
{
sum = state->cur_sum + state->char_set[i];
if (sum <= state->N)
{
state->buf[state->pos++] = state->char_set[i];
state->cur_sum = sum;
if (sum == state->N)
{
state->buf[state->pos] = '\0';
printf ("\r %s\r\n", state->buf);
}
else
{
think (state);
state->pos--;
state->cur_sum -= sum;
}
}
}
}
int main()
{
#if 0
char char_set[] = "zyxwvustrqponmlkjihgfedcbaZYXWVUSTRQPONMLKJIHGFEDCBA";
#else
char char_set[] = "ZYXWVUSTRQPONMLKJIHGFEDCBA";
#endif
int N = 195;
think_state state;
#if 0
printf ("\r passwd: ");
scanf("%d", &N);
#endif
if (N < MIN_N || N > MAX_N)
{
printf ("\r Invalid Input\r\n");
return 1;
}
memset (&state, 0, sizeof(think_state));
state.char_set = char_set;
state.N = N;
think(&state);
return 0;
}