summaryrefslogtreecommitdiff
path: root/keymash.c
diff options
context:
space:
mode:
authoraxtlos <axtlos@getcryst.al>2024-04-04 17:26:17 +0200
committeraxtlos <axtlos@getcryst.al>2024-04-04 17:26:17 +0200
commit0ff98491b549e71274b3d7d96ed2b9dc250e55ab (patch)
tree0bf24d36692a4d856341121acd12babdd4078441 /keymash.c
downloadgenkeymash-0ff98491b549e71274b3d7d96ed2b9dc250e55ab.tar.gz
genkeymash-0ff98491b549e71274b3d7d96ed2b9dc250e55ab.tar.bz2
Add program
Diffstat (limited to 'keymash.c')
-rw-r--r--keymash.c64
1 files changed, 64 insertions, 0 deletions
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 <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;
+
+}