Dev_Vernam/prgm/codage.c

60 lines
1.1 KiB
C
Raw Normal View History

2022-12-15 22:27:05 +01:00
#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);
2022-12-16 09:01:00 +01:00
/* Traitement erreur */
//fclose(f_m);
2022-12-15 22:27:05 +01:00
//2
f_k = fopen(cheminFic_k, "wb");
2022-12-16 09:01:00 +01:00
while (f_k)
2022-12-15 22:27:05 +01:00
{
fwrite(cle, sizeof(char), count, f_k);
2022-12-16 09:01:00 +01:00
}
fclose(f_k);
2022-12-15 22:27:05 +01:00
f_k = fopen(cheminFic_k, "r");
/* Traitement erreur */
2022-12-16 09:01:00 +01:00
//fclose(f_k);
2022-12-15 22:27:05 +01:00
//3
2022-12-16 09:01:00 +01:00
f_mc = fopen(cheminFic_mc, "wb");
2022-12-15 22:27:05 +01:00
/* Traitement erreur */
2022-12-16 09:01:00 +01:00
//fclose(f_mc);
2022-12-15 22:27:05 +01:00
2022-12-16 09:01:00 +01:00
//f_m = fopen(cheminFic_m, "r");
//f_k = fopen(cheminFic_k, "r");
//f_mc = fopen(cheminFic_mc, "wb");
2022-12-15 22:27:05 +01:00
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;
}