/* crypto.c * * Copyright 2024 axtlos * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * SPDX-License-Identifier: GPL-3.0-only */ #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'}; unsigned int get_data(char *file) { unsigned int ret = 0; FILE *data = NULL; if (file) { data = fopen (file, "r"); } else { data = stdin; } unsigned int character; while ((character = fgetc (data)) != EOF) { ret = ret + character; } return ret; } int main (int argc, char *argv[]) { char *keymash = malloc(33); int r,total = 0; char prev = 'a'; int val = 0; int switchup = 0; int from_stdin = argc > 1 ? 1 : 0; unsigned int data = 0; data = get_data (from_stdin == 0 ? NULL : argv[argc-1]); srand(data); total += sprintf(keymash+total, "%c", prev); while (total < 32) { if (val == 0) { int j = total+2 < 32 ? 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]; } else { i -= 1; } } switchup = switchup < 0 ? 0 : switchup+1; } else if (val == 1) { int j = total+2 < 32 ? 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; }