From 150f938a8ec6297d1f6acc542486bb5556fdceed Mon Sep 17 00:00:00 2001 From: Liam Waldron Date: Tue, 3 Dec 2024 09:27:41 -0500 Subject: [PATCH] init --- README.md | 15 +++++++++ src/hellmath/Makefile | 6 ++++ src/hellmath/main.c | 35 +++++++++++++++++++++ src/keygen/Makefile | 9 ++++++ src/keygen/config.mk | 6 ++++ src/keygen/main.c | 71 +++++++++++++++++++++++++++++++++++++++++++ src/keygen/test.c | 8 +++++ src/keygen/test.h | 6 ++++ src/rng/main.c | 29 ++++++++++++++++++ 9 files changed, 185 insertions(+) create mode 100644 README.md create mode 100644 src/hellmath/Makefile create mode 100644 src/hellmath/main.c create mode 100644 src/keygen/Makefile create mode 100644 src/keygen/config.mk create mode 100644 src/keygen/main.c create mode 100644 src/keygen/test.c create mode 100644 src/keygen/test.h create mode 100644 src/rng/main.c diff --git a/README.md b/README.md new file mode 100644 index 0000000..2967cf2 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Highly Extreme Level Language Standard Library (stdhell) + +stdhell is the standard library for my terrible programming language called HELL. + +# Rationale + +99% of hell just rips off the system's standard c library but for things that aren't there, I made this. + +Some of these libraries are provided for abstraction, however. For example, the `rng` library provides a simple PRNG. + +Same for the keygen library. + +# Copyright + +LGPL v3.0 or later diff --git a/src/hellmath/Makefile b/src/hellmath/Makefile new file mode 100644 index 0000000..44c0df7 --- /dev/null +++ b/src/hellmath/Makefile @@ -0,0 +1,6 @@ +lib: main.c + $(CC) main.c -c -o hellmath.o + $(AR) -rc hellmath.a hellmath.o + +install: hellmath.a + install hellmath.a $(PREFIX)/lib/stdhell diff --git a/src/hellmath/main.c b/src/hellmath/main.c new file mode 100644 index 0000000..c8f659f --- /dev/null +++ b/src/hellmath/main.c @@ -0,0 +1,35 @@ +/* + * main.c - Main library for hellmath + * + * This file is part of stdhell. + * + * Stdhell 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, either + * version 3 of the License, or (at your option) any later version. + * + * Stdhell 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 Stdhell. If + * not, see . + */ + +int +check_prime(int n) +{ + int divisors; + + for (int i = 2; i <= n - 1; i++) { + if (n % i == 0) { + divisors++; + } + } + + if (divisors > 0) { + return 1; + } + else { + return 0; + } +} diff --git a/src/keygen/Makefile b/src/keygen/Makefile new file mode 100644 index 0000000..4989439 --- /dev/null +++ b/src/keygen/Makefile @@ -0,0 +1,9 @@ +include config.mk + +all: + $(CC) -c main.c + $(AR) -rc keygen.a main.o + +clean: + rm main.o + rm keygen.a diff --git a/src/keygen/config.mk b/src/keygen/config.mk new file mode 100644 index 0000000..fee0bb0 --- /dev/null +++ b/src/keygen/config.mk @@ -0,0 +1,6 @@ +# +# config.mk +# + +CC = /bin/gcc +AR = /bin/ar diff --git a/src/keygen/main.c b/src/keygen/main.c new file mode 100644 index 0000000..574d20c --- /dev/null +++ b/src/keygen/main.c @@ -0,0 +1,71 @@ +/* + main.c - keygen library + + This file is part of stdhell. + + stdhell 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, either version 3 of the License, or (at your + option) any later version. + + stdhell 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 stdhell. If not, see . +*/ + +#include +#include +#include +#include + +void +keygen_gen(int N) +{ + int c = 0; + int randomizer = 0; + + srand((unsigned int)(time(NULL))); + + /* Characters to use for string generation */ + char numbers[] = "1234567890"; + char letter[] = "qwertyuiopasdfghjklzxcvbnm"; + char LETTER[] = "QWERTYUIOPASDFGHJKLZXCVBNM"; + char symbols[] = "!@#$%^&*?"; + + /* Variable for each individual password character */ + char password[N]; + + /* Completed password string */ + char complete_key[N]; + + randomizer = rand() % 4; + + for (c = 0; c < N; c++) { + switch (randomizer) { + case 1: + password[c] = numbers[rand() % 10]; + randomizer = rand() % 4; + complete_key[c] = password[c]; + break; + case 2: + password[c] = symbols[rand() % 8]; + randomizer = rand() % 4; + complete_key[c] = password[c]; + break; + case 3: + password[c] = LETTER[rand() % 26]; + randomizer = rand() % 4; + complete_key[c] = password[c]; + break; + default: + password[c] = letter[rand() % 26]; + randomizer = rand() % 4; + complete_key[c] = password[c]; + } + } + return 0; +} diff --git a/src/keygen/test.c b/src/keygen/test.c new file mode 100644 index 0000000..85e5bd9 --- /dev/null +++ b/src/keygen/test.c @@ -0,0 +1,8 @@ +#include "test.h" + +int +main() +{ + keygen_gen(30); + printf("%s\n", complete_key[]); +} diff --git a/src/keygen/test.h b/src/keygen/test.h new file mode 100644 index 0000000..1c8b215 --- /dev/null +++ b/src/keygen/test.h @@ -0,0 +1,6 @@ +#ifndef TEST_H_ +#define TEST_H_ + +void keygen_gen(int N); + +#endif diff --git a/src/rng/main.c b/src/rng/main.c new file mode 100644 index 0000000..cfa6a2b --- /dev/null +++ b/src/rng/main.c @@ -0,0 +1,29 @@ +/* + main.c - keygen library + + This file is part of stdhell. + + stdhell 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, either version 3 of the License, or (at your + option) any later version. + + stdhell 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 stdhell. If not, see . +*/ + +#include +#include +#include + +int +rng_randint() +{ + srand(time(0)); + int n = rand(); +}