init
This commit is contained in:
9
src/config.h
Normal file
9
src/config.h
Normal 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
61
src/main.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user