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
|
# SPDX-License-Identifier: BSD-3-Clause
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
const char start[10] = {'s','s','s','d','d','d','f','f','f','f'};
const char end[11] = {'g','g','g','h','h','h','j','k','l','l','l'};
int
main (int argc, char *argv[]) {
if (argc <= 1) {
puts("Give me the keymash length!");
return 1;
}
int keymashlength = atoi(argv[1]);
char *keymash = malloc(keymashlength+1);
int r,total = 0;
char prev = 'a';
int val = 0;
int switchup = 0;
srand(time(NULL));
total += sprintf(keymash+total, "%c", prev);
while (total < keymashlength) {
if (val == 0) {
int j = total+2 < keymashlength ? 2 : 1;
for (int i = 0; i < j; i++) {
r = abs((rand() % 10 - r) + r);
if (prev != start[r]) {
total += sprintf(keymash+total, "%c", start[r]);
prev = start[r];
//total += 1;
} else {
i -= 1;
}
}
switchup = switchup < 0 ? 0 : switchup+1;
} else if (val == 1) {
int j = total+2 < keymashlength ? 2 : 1;
for (int i = 0; i < j; i++) {
r = abs((rand() % 11));
if (prev != end[r]) {
total += sprintf(keymash+total, "%c", end[r]);
prev = end[r];
} else {
i -= 1;
}
}
switchup = switchup > 0 ? 0 : switchup-1;
}
if (switchup < 2 || switchup > -2) {
val = abs(rand() % 2);
} else {
val = switchup < 0 ? 0 : 1;
}
}
puts(keymash);
free(keymash);
return 0;
}
|