From 0ff98491b549e71274b3d7d96ed2b9dc250e55ab Mon Sep 17 00:00:00 2001 From: axtlos Date: Thu, 4 Apr 2024 17:26:17 +0200 Subject: Add program --- keymash.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 keymash.c (limited to 'keymash.c') diff --git a/keymash.c b/keymash.c new file mode 100644 index 0000000..80deb16 --- /dev/null +++ b/keymash.c @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: BSD-3-Clause + +#include +#include +#include +#include +#include + +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; + +} -- cgit v1.2.3