Dev_Vernam/prgm/generate.c

43 lines
749 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 16:59:35 +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
2022-12-16 16:59:35 +01:00
//Crée la nouvelle clé à partir du nombre de caractères du message
for(a=0;a<(count-2);a++)
{
2022-12-15 22:27:05 +01:00
i = rand()%26;
cle[a]=characteres[i];
2022-12-16 16:59:35 +01:00
}
for (a=1;a<3;a++)
{
2022-12-16 12:28:09 +01:00
i = rand()%26;
cle[count-a]=characteres[i];
2022-12-16 16:59:35 +01:00
}
2022-12-16 12:28:09 +01:00
f = fopen (argv[3], "w");
2022-12-16 16:59:35 +01:00
//Ecris la clé précédemmant créée dans le fichier cle.txt par exemple
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;
}