55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include <sys/time.h>
|
|
#include <string.h>
|
|
|
|
#define BUFFER_SIZ 8192
|
|
|
|
|
|
char pool[] = {
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
|
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
|
'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
|
|
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
|
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
|
'Y', 'Z', '!', '@', '#', '$', '%', '^', '&', '*',
|
|
'[', ']', '\\', '|', ';', '\'', ',', '.', '/', '{', '}', ':', '"', '<', '>', '?'
|
|
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int PASSWD_LEN = 16;
|
|
struct timeval tpstart;
|
|
char password[BUFFER_SIZ];
|
|
int i = 0;
|
|
|
|
|
|
if (argv[1] != NULL)
|
|
{
|
|
PASSWD_LEN = atoi(argv[1]);
|
|
}
|
|
|
|
if (PASSWD_LEN >= BUFFER_SIZ)
|
|
{
|
|
printf("Password too long!\n");
|
|
exit(1);
|
|
}
|
|
|
|
memset(password, 0, BUFFER_SIZ);
|
|
gettimeofday(&tpstart, NULL);
|
|
srand(tpstart.tv_usec);
|
|
|
|
while (i != PASSWD_LEN) {
|
|
password[i++] = pool[rand() % sizeof(pool)];
|
|
}
|
|
|
|
printf("%s\n", password);
|
|
|
|
return 0;
|
|
}
|
|
|