Dev_Vernam/prgm/generate.c

31 lines
638 B
C
Raw Normal View History

2022-12-15 22:27:05 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
2022-12-16 12:28:09 +01:00
#include <string.h>
2022-12-15 22:27:05 +01:00
#include "fonctions.h"
2022-12-16 12:28:09 +01:00
int generate(int count,int argc,char *argv[])
2022-12-15 22:27:05 +01:00
{
2022-12-16 12:28:09 +01:00
FILE *f;
2022-12-15 22:27:05 +01:00
char cle[count];
int a,i;
char characteres[26]="azertyuiopqsdfghjklmwxcvbn";
srand(time(NULL));
2022-12-16 12:28:09 +01:00
for(a=0;a<(count-2);a++) { /*on fait donc une première boucle*/
2022-12-15 22:27:05 +01:00
i = rand()%26;
cle[a]=characteres[i];
2022-12-16 12:28:09 +01:00
}
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);
2022-12-15 22:27:05 +01:00
return EXIT_SUCCESS;
}