blob: 3a12820505a6f37aa839d45a3d703144132a4924 (
plain)
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 <stdint.h>
#include <stdlib.h>
char* incr(char password[8]) {
int i, rollover = 1;
for(i = 7; (i >= 0) && rollover; i--) {
if(password[i] == 'z') {
password[i] = 'a';
} else {
password[i] += 1;
rollover = 0;
}
}
return password;
}
char check(char* password) {
char i, flags = 2, firstpair = 0;
for(i = 0; i < 5; i++)
if(password[i+1] == password[i] + 1 && password[i+2] == password[i] + 2)
flags |= 1;
for(i = 0; i < 8; i++)
if(password[i] == 'i' || password[i] == 'o' || password[i] == 'l')
flags &= (~2);
for(i = 0; i < 7; i++) {
if(password[i] == password[i+1]) {
if(firstpair) {
if(password[i] != firstpair)
flags |= 4;
}
else
firstpair = password[i];
i++;
}
}
return (flags == 7);
}
char* next(char* password) {
char good = 0;
while(!good) {
password = incr(password);
good = check(password);
}
return password;
}
int main() {
char *password;
password = malloc(10*sizeof(char));
scanf("%s", password);
password = next(password);
printf("First new password: %s\n", password);
password = next(password);
printf("Second new password: %s\n", password);
free(password);
return 0;
}
|