62 lines
1.1 KiB
C
62 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <time.h>
|
||
|
#include "fonctions.h"
|
||
|
|
||
|
int codage(int argc, char *argv[]) {
|
||
|
FILE *f_m, *f_k, *f_mc; /* strcutures permettant, une fois FOPEN
|
||
|
exécuté de recupérer des informations pour manipuler les fichiers
|
||
|
en C */
|
||
|
int c;
|
||
|
int k1;
|
||
|
int calcul;
|
||
|
int count;
|
||
|
char cle[100];
|
||
|
char * cheminFic_m = "message.txt";
|
||
|
char * cheminFic_k = "cle.txt";
|
||
|
char * cheminFic_mc = "message_c.txt";
|
||
|
|
||
|
//1
|
||
|
f_m = fopen(cheminFic_m, "r");
|
||
|
for (c = getc(f_m); c != EOF; c = getc(f_m))
|
||
|
{
|
||
|
count = count + 1;
|
||
|
}
|
||
|
generate(count);
|
||
|
fclose(f_m);
|
||
|
|
||
|
//2
|
||
|
f_k = fopen(cheminFic_k, "wb");
|
||
|
if (f_k)
|
||
|
{
|
||
|
fwrite(cle, sizeof(char), count, f_k);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return EXIT_FAILURE;
|
||
|
}
|
||
|
f_k = fopen(cheminFic_k, "r");
|
||
|
/* Traitement erreur */
|
||
|
fclose(f_k);
|
||
|
|
||
|
//3
|
||
|
f_mc = fopen(cheminFic_mc, "w");
|
||
|
/* Traitement erreur */
|
||
|
fclose(f_mc);
|
||
|
|
||
|
f_m = fopen(cheminFic_m, "r");
|
||
|
f_k = fopen(cheminFic_k, "r");
|
||
|
f_mc = fopen(cheminFic_mc, "wb");
|
||
|
while ((c = fgetc(f_m)) != EOF)
|
||
|
{
|
||
|
k1 = fgetc(f_k);
|
||
|
calcul = (c+k1) % 256;
|
||
|
fputc(calcul, f_mc);
|
||
|
}
|
||
|
fclose(f_m);
|
||
|
fclose(f_k);
|
||
|
fclose(f_mc);
|
||
|
|
||
|
return EXIT_SUCCESS;
|
||
|
|
||
|
}
|