1ère version
This commit is contained in:
parent
c246c027ff
commit
ca5750ea71
17
prgm/Makefile
Normal file
17
prgm/Makefile
Normal file
@ -0,0 +1,17 @@
|
||||
run : codage.o decodage.o code.o generate.o
|
||||
gcc -o run codage.o decodage.o code.o generate.o
|
||||
|
||||
codage.o : codage.c
|
||||
gcc -o codage.o -c codage.c
|
||||
|
||||
decodage.o : decodage.c
|
||||
gcc -o decodage.o -c decodage.c
|
||||
|
||||
code.o : code.c
|
||||
gcc -o code.o -c code.c
|
||||
|
||||
generate.o : generate.c
|
||||
gcc -o generate.o -c generate.c
|
||||
|
||||
clean :
|
||||
rm -f *.o
|
1
prgm/cle.txt
Normal file
1
prgm/cle.txt
Normal file
@ -0,0 +1 @@
|
||||
azertyuiopqsdfghjklmwxcvbn
|
62
prgm/codage.c
Normal file
62
prgm/codage.c
Normal file
@ -0,0 +1,62 @@
|
||||
#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;
|
||||
|
||||
}
|
32
prgm/code.c
Normal file
32
prgm/code.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "fonctions.h"
|
||||
|
||||
int main(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 option;
|
||||
|
||||
/* recupération sur la ligne de commande des noms de fichiers et option (-c pour codage
|
||||
-d pour décodage : message cle message_calculé
|
||||
|
||||
code -c f1 f2 f3
|
||||
code -d f1 f2 f3
|
||||
|
||||
*/
|
||||
|
||||
if (argv[1]=="-c"){
|
||||
codage(argc, argv);
|
||||
}
|
||||
|
||||
else if (argv[1]=="-d"){
|
||||
decodage(argc, argv);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
37
prgm/decodage.c
Normal file
37
prgm/decodage.c
Normal file
@ -0,0 +1,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int decodage(int argc, char *argv[]) {
|
||||
FILE *f_m, *f_k, *f_mdc; /* strcutures permettant, une fois FOPEN
|
||||
exécuté de recupérer des informations pour manipuler les fichiers
|
||||
en C */
|
||||
int c;
|
||||
int k1;
|
||||
int calcul;
|
||||
|
||||
char * cheminFic_m = "message_c.txt";
|
||||
f_m = fopen(cheminFic_m, "r");
|
||||
if (f_m==NULL){
|
||||
printf("L'ouverture du fichier à échouer. Veuillez verifier l'existence de celui-ci.\n");
|
||||
}
|
||||
|
||||
char * cheminFic_k = "cle.txt";
|
||||
f_k = fopen(cheminFic_k, "r");
|
||||
if (f_k==NULL){
|
||||
printf("L'ouverture du fichier à échouer. Veuillez verifier l'existence de celui-ci.\n");
|
||||
}
|
||||
|
||||
char * cheminFic_mdc = "message_dc.txt";
|
||||
f_mdc = fopen(cheminFic_mdc, "w");
|
||||
if (f_mdc==NULL){
|
||||
printf("L'ouverture du fichier à échouer. Veuillez verifier l'existence de celui-ci.\n");
|
||||
}
|
||||
|
||||
/*fermeture des fichiers*/
|
||||
fclose(f_m);
|
||||
fclose(f_k);
|
||||
fclose(f_mdc);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
8
prgm/fonctions.h
Normal file
8
prgm/fonctions.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef FONCTIONS
|
||||
#define FONCTIONS
|
||||
|
||||
int codage(int argc, char* argv[]);
|
||||
int decodage(int argc, char* argv[]);
|
||||
int generate(int count);
|
||||
|
||||
#endif
|
18
prgm/generate.c
Normal file
18
prgm/generate.c
Normal file
@ -0,0 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "fonctions.h"
|
||||
|
||||
int generate(int count)
|
||||
{
|
||||
char cle[count];
|
||||
int a,i;
|
||||
char characteres[26]="azertyuiopqsdfghjklmwxcvbn";
|
||||
srand(time(NULL));
|
||||
for(a=0;a<count;a++)
|
||||
{
|
||||
i = rand()%26;
|
||||
cle[a]=characteres[i];
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
1
prgm/message.txt
Normal file
1
prgm/message.txt
Normal file
@ -0,0 +1 @@
|
||||
txt a encoder
|
0
prgm/message_c.txt
Normal file
0
prgm/message_c.txt
Normal file
Loading…
Reference in New Issue
Block a user