From e779d47a10c9764d4ed199993f7188bf66410582 Mon Sep 17 00:00:00 2001 From: Liam Waldron Date: Thu, 30 Mar 2023 14:14:12 -0400 Subject: [PATCH] init --- Makefile | 15 +++++++++++++++ README | 13 +++++++++++++ config.mk | 5 +++++ src/libecrypt.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100644 config.mk create mode 100644 src/libecrypt.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6f6fdbb --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +include config.mk + +static: src/libecrypt.c + $(CC) -c src/libecrypt.c -o + ar -rc src/libecrypt.a src/libecrypt.o + +shared: src/libecrypt.c + $(CC) -c -fpic src/libecrypt.c + $(CC) -shared src/libecrypt.o libecrypt.so + +install-static: src/libecrypt.a + install --mode=0755 src/libecrypt.a $(PREFIX)/lib + +install-shared: src/libecrypt.so + install --mode=0755 src/libecrypt.so $(PREFIX)/lib diff --git a/README b/README new file mode 100644 index 0000000..4c432bb --- /dev/null +++ b/README @@ -0,0 +1,13 @@ ++ libecrypt + +A library which provides a random string generation function. + ++ Usage + + int main() { + ecrypt(PASSWD_LENGTH); + } + ++ Installation + +Run 'make static' to compile a static library, or 'make shared' to compile a shared library. Then, run 'make install-static' or 'make install-shared' depending on what you ran previously. diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..40c0e7e --- /dev/null +++ b/config.mk @@ -0,0 +1,5 @@ +# +# config.mk +# + +PREFIX = /usr diff --git a/src/libecrypt.c b/src/libecrypt.c new file mode 100644 index 0000000..b026a6b --- /dev/null +++ b/src/libecrypt.c @@ -0,0 +1,45 @@ +/* libecrypt - library for including ecrypt functions in programs */ + +#include +#include +#include +#include + +void ecrypt(int N) { + int c = 0; + int randomizer = 0; + + srand((unsigned int)(time(NULL))); + + char numbers[] = "1234567890"; + char letter[] = "qwertyuiopasdfghjklzxcvbnm"; + char LETTER[] = "QWERTYUIOPASDFGHJKLZXCVBNM"; + char symbols[] = "!@#$%^&*?"; + char password[N]; + + randomizer = rand() % 4; + + for (c = 0; c < N; c++) { + switch (randomizer) { + case 1: + password[c] = numbers[rand() % 10]; + randomizer = rand() % 4; + printf("%c", password[c]); + break; + case 2: + password[c] = symbols[rand() % 8]; + randomizer = rand() % 4; + printf("%c", password[c]); + break; + case 3: + password[c] = LETTER[rand() % 26]; + randomizer = rand() % 4; + printf("%c", password[c]); + break; + default: + password[c] = letter[rand() % 26]; + randomizer = rand() % 4; + printf("%c", password[c]); + } + } +}