This commit is contained in:
Liam Waldron 2023-03-30 14:14:12 -04:00
commit e779d47a10
4 changed files with 78 additions and 0 deletions

15
Makefile Normal file
View File

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

13
README Normal file
View File

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

5
config.mk Normal file
View File

@ -0,0 +1,5 @@
#
# config.mk
#
PREFIX = /usr

45
src/libecrypt.c Normal file
View File

@ -0,0 +1,45 @@
/* libecrypt - library for including ecrypt functions in programs */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
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]);
}
}
}