init
This commit is contained in:
commit
e779d47a10
15
Makefile
Normal file
15
Makefile
Normal 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
13
README
Normal 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.
|
45
src/libecrypt.c
Normal file
45
src/libecrypt.c
Normal 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]);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user