commit 845eddafd402b0510ee3b3289234c2e432997aa7 Author: Liam Waldron Date: Fri Mar 24 11:22:19 2023 -0400 init diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b370c5a --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +include config.mk + +all: src/main.c + $(CC) $(CFLAGS) $(LDFLAGS) src/main.c -o src/ecrypt + +install: src/ecrypt + install src/ecrypt $(PREFIX)/bin diff --git a/README b/README new file mode 100644 index 0000000..ddd2662 --- /dev/null +++ b/README @@ -0,0 +1,22 @@ ++ ecrypt - a simple key/password generator + +ecrypt is an extremely simple and basic encryption tool. It does not aim to provide +advanced encryption features that other tools may offer, it simply acts as a random +string generator. + ++ Installation + +Clone this repository: + (user)$ git clone https://git.everestlinux.org/EverestLinux/ecrypt + +Edit src/config.h and ensure it looks good: + (user)$ $EDITOR src/config.h + +Edit config.mk and adjust any options: + (user)$ $EDITOR config.mk + +Run make: + (user)$ make + +Install: + (root)# make install diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..d92a463 --- /dev/null +++ b/config.mk @@ -0,0 +1,9 @@ +# +# config.mk +# + +PREFIX = /usr + +CC = cc +CFLAGS = -O2 -fstack-protector-strong +LDFLAGS = -s -static diff --git a/include/colors.h b/include/colors.h new file mode 100644 index 0000000..435cdd3 --- /dev/null +++ b/include/colors.h @@ -0,0 +1,9 @@ +/* colors.h - define output colors */ + +#ifndef COLORS_H_ +#define COLORS_H_ + +#define ANSI_COLOR_BLUE "\x1b[34m" +#define ANSI_COLOR_RESET "\x1b[0m" + +#endif diff --git a/src/config.h b/src/config.h new file mode 100644 index 0000000..15cf7cb --- /dev/null +++ b/src/config.h @@ -0,0 +1,9 @@ +/* config.h - define configuration values */ + +#ifndef CONFIG_H_ +#define CONFIG_H_ + +/* Length of password to be outputted */ +#define PASSWD_LENGTH 30 + +#endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..8f1cd09 --- /dev/null +++ b/src/main.c @@ -0,0 +1,61 @@ +/* ecrypt - generate keys */ + +#include +#include +#include +#include + +/* define ANSI_COLOR_BLUE and ANSI_COLOR_RESET */ +#include "../include/colors.h" + +/* include configuration file */ +#include "config.h" + +void randPasswdGen(int N) { + int c = 0; /* init counter */ + int randomizer = 0; + + srand((unsigned int)(time(NULL))); + + char numbers[] = "1234567890"; + char letter[] = "abcdefghijklmnopqrstuvwxyz"; + char LETTER[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + char symbols[] = "!@#$%^&*?"; + char password[N]; + + randomizer = rand() % 4; + + /* this is a bit ugly but it gets the job done */ + for (c = 0; c < N; c++) { + switch (randomizer) { + case 1: + password[c] = numbers[rand() % 10]; + randomizer = rand() % 4; + printf(ANSI_COLOR_BLUE "%c" ANSI_COLOR_RESET, password[c]); + break; + case 2: + password[c] = symbols[rand() % 8]; + randomizer = rand() % 4; + printf(ANSI_COLOR_BLUE "%c" ANSI_COLOR_RESET, password[c]); + break; + case 3: + password[c] = LETTER[rand() % 26]; + randomizer = rand() % 4; + printf(ANSI_COLOR_BLUE "%c" ANSI_COLOR_RESET, password[c]); + break; + default: + password[c] = letter[rand() % 26]; + randomizer = rand() % 4; + printf(ANSI_COLOR_BLUE "%c" ANSI_COLOR_RESET, password[c]); + } + } +} + +int main() { + int N = PASSWD_LENGTH; /* password length, can be customized by config.h */ + + randPasswdGen(N); + printf("\n"); /* remove newline character for zsh users */ + + return 0; +}