This commit is contained in:
Liam Waldron 2023-03-24 11:22:19 -04:00
commit 845eddafd4
6 changed files with 117 additions and 0 deletions

7
Makefile Normal file
View File

@ -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

22
README Normal file
View File

@ -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

9
config.mk Normal file
View File

@ -0,0 +1,9 @@
#
# config.mk
#
PREFIX = /usr
CC = cc
CFLAGS = -O2 -fstack-protector-strong
LDFLAGS = -s -static

9
include/colors.h Normal file
View File

@ -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

9
src/config.h Normal file
View File

@ -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

61
src/main.c Normal file
View File

@ -0,0 +1,61 @@
/* ecrypt - generate keys */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* 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;
}