1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <stdio.h>
#include <time.h>
// Un caractère au random
char randomOne()
{
int randResult = rand() % (40 + 1);
int randCara;
char alphaMin[] = "abcdefghijklmnopqrstuvwxyz";
char alphaMaj[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char specialCara[] = "&~#'{([-|_@)]=}+$%*!:/;.,?";
char result;
if(randResult < 11)
{
randCara = rand() % (25 + 1);
result = alphaMin[randCara];
}
else if(randResult < 21)
{
randCara = rand() % (25 + 1);
result = alphaMaj[randCara];
}
else if(randResult < 31)
{
result = rand() % (9);
}
else
{
randCara = rand() % (26 + 1);
result = specialCara[randCara];
}
return result;
}
int main(int argc, char *argv[])
{
int totalSize = atoi(argv[1]);
int count = 0;
char pwd;
// Initialise rand seed
srand(time(NULL));
if(argc != 2)
{
printf("Use one argv. No more \nGenCryPWD [CodeSize/max250]");
return 0;
}
// Construction du pwd
while(count < totalSize)
{
if(count == 0)
{
pwd = randomOne();
}
else
{
pwd = pwd + randomOne();
}
++count;
}
printf("%c", pwd);
return 0;
} |