Dev_Vernam/prgm/generate.c
2022-12-16 12:28:09 +01:00

31 lines
638 B
C

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "fonctions.h"
int generate(int count,int argc,char *argv[])
{
FILE *f;
char cle[count];
int a,i;
char characteres[26]="azertyuiopqsdfghjklmwxcvbn";
srand(time(NULL));
for(a=0;a<(count-2);a++) { /*on fait donc une première boucle*/
i = rand()%26;
cle[a]=characteres[i];
}
for (a=1;a<3;a++){
i = rand()%26;
cle[count-a]=characteres[i];
}
f = fopen (argv[3], "w");
if (f) {
fwrite (cle, sizeof(char), count, f);
} else {
return EXIT_FAILURE;
}
fclose (f);
return EXIT_SUCCESS;
}