From 33eca360a97dae7aab5e8d30376759aa9fc34c61 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Sat, 29 Jun 2024 23:00:12 -0500 Subject: Add argp shit --- src/main.c | 119 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 46 deletions(-) diff --git a/src/main.c b/src/main.c index dc9e0bd..2e6c13a 100644 --- a/src/main.c +++ b/src/main.c @@ -19,15 +19,57 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include +#define PHRASESIZE 32 + +const char *argp_program_version = "Alpha-0.1"; +const char *argp_program_bug_address = "@syxhe on Telegram (https://t.me/syxhe)"; + +static char doc[] = "lol"; +static char argdoc[] = "lmao"; + +static struct argp_option options[] = { + {.name = "passphrase", .key = 'p', .arg = "key", .flags = 0, .doc = "Specify passphrase for encryption/decryption", .group = 0}, + {"decrypt", 'd', 0, 0, "Skip the slots minigame and immediately decrypt (or encrypt) files", 0}, + {0} +}; + +struct arguments { + char *inputpass; + int skipslots; +}; + +static error_t parse_opt(int key, char *arg, struct argp_state *state) { + struct arguments *args = state->input; + + switch(key) { + case 'p': + args->inputpass = arg; + break; + + case 'd': + args->skipslots = 1; + break; + + default: + return ARGP_ERR_UNKNOWN; + } + + return 0; +} + +static struct argp argp = {options, parse_opt, argdoc, doc, NULL, 0, 0}; + // Stolen from stackoverflow. Thanks Laurence (https://stackoverflow.com/a/822361) int randint(int n) { if ((n - 1) == RAND_MAX) { @@ -68,40 +110,40 @@ char* genphrase(size_t phrasesize) { return phrase; } -// Initialize random()'s seed. Return values indicate quality of initialization: 0 = best, 3 = worst -int initseed() { - char randbytes[256]; unsigned int seed = 0; - int fail[2] = {0, 0}; - if(getrandom(randbytes, sizeof(randbytes), 0) < 0) { - error(0, errno, "Couldn't get random bytes for initstate"); - fail[0] = 1; - } - if(getrandom(&seed, sizeof(seed), 0) < 0) { - error(0, errno, "Couldn't get random bytes for seed"); - fail[1] = 1; - } - // Gross I know but I haven't slept in a day and don't care anymore - if(fail[0] && fail[1]) { // Couldn't get either randombyte - srand(time(NULL)); - return 3; - } else if(fail[0] && !fail[1]) { // Couldn't get initstate array - srand(seed); - return 2; - } else if(fail[1] && !fail[0]) { // Couldn't get seed - initstate(time(NULL), randbytes, sizeof(randbytes)); - return 1; - } else { - initstate(seed, randbytes, sizeof(randbytes)); - } +int main(int argc, char *argv[]) { + struct arguments args; + args.inputpass = NULL; + args.skipslots = 0; - return 0; -} + argp_parse(&argp, argc, argv, ARGP_NO_ARGS, 0, &args); -int main() { - /* + if(args.inputpass != NULL) { + if(strlen(args.inputpass) != PHRASESIZE) { + error(1, 0, "Encryption passphrase must be exactly %d characters long", PHRASESIZE); + } - // Get files + printf("Using input passphrase \"%s\"\n", args.inputpass); + } else { + // Fuck you + srandom((unsigned int)time(NULL)); + + char phrase[PHRASESIZE]; + for(size_t i = 0; i < sizeof(phrase); i++) { + phrase[i] = randint(25 + 1) + 65; + if(random() > (RAND_MAX / 2)) + phrase[i] += 32; + } + + printf("Encryption phrase: %s\n\nWrite this phrase down EXACTLY if you want to recover your files\n", phrase); + + if(args.skipslots == 0) { + printf("Hit Enter to contine, or CTRL+C to cancel..."); + getchar(); + } + } + + /* Get files struct nodelist *files = scanfiles("./", alphasort); // Encrypt those files @@ -112,27 +154,12 @@ int main() { continue; } - passencblock(fd, "We do a little trolling"); + passencblock(fd, phrase); close(fd); } nodelist_delete(files); //*/ - //initseed(); - - // ok something is fucking up in the initseed function that isn't fucking up here. Great - srand(time(NULL)); - - // WHY THE FUCK IS THIS CRASHING - char phrase[32]; - for(size_t i = 0; i < sizeof(phrase); i++) { - phrase[i] = randint(25 + 1) + 65; - if(random() > (RAND_MAX / 2)) - phrase[i] += 32; - } - - printf("%s\n", phrase); - return 0; } \ No newline at end of file -- cgit v1.2.3