| 作者 | SHA1 | 备注 | 提交日期 |
|---|---|---|---|
|
|
23f92020d0 | Dechiffre à la place de chiffre | 5 年前 |
|
|
707bc90ae9 | Ajout gitignore, ajout des extern et static, mise à jour du Makefile | 5 年前 |
| @@ -0,0 +1,2 @@ | |||
| pass | |||
| *.o | |||
| @@ -1,5 +1,11 @@ | |||
| pass: pass.c pass.h chiffre.c chiffre.h | |||
| cc -Wall -D_REENTRANT -o pass pass.c chiffre.c -pthread | |||
| pass: pass.o chiffre.o | |||
| cc -o pass pass.o chiffre.o -pthread | |||
| pass.o: pass.c pass.h | |||
| cc -c -Wall -D_REENTRANT pass.c | |||
| chiffre.o: chiffre.c chiffre.h | |||
| cc -c -Wall -D_REENTRANT chiffre.c | |||
| clean: | |||
| rm -f pass | |||
| rm -f pass *.o | |||
| @@ -10,7 +10,7 @@ | |||
| #ifdef XOR_SIMPLE | |||
| long long CLE = 0xABCD1276FA8745EC; // clé simple de 64 bits | |||
| static long long CLE = 0xABCD1276FA8745EC; // clé simple de 64 bits | |||
| /* Fonction de chiffrement avec xOR, en utilisant une clé fixe de 64 bits. */ | |||
| void chiffre_xor_simple(char *buf, int l) | |||
| @@ -35,8 +35,8 @@ void chiffre_xor_simple(char *buf, int l) | |||
| #endif | |||
| #ifdef XOR_FICHIER | |||
| char *NFCLE = "/tmp/clepass"; // nom du fichier utilisé pour la clé | |||
| char BCLE[LCLE]; // buffer contenant la clé | |||
| static char *NFCLE = "/tmp/clepass"; // nom du fichier utilisé pour la clé | |||
| static char BCLE[LCLE]; // buffer contenant la clé | |||
| /* Gestion des clés à partir d'un fichier externe. */ | |||
| int init_cle_xor_fichier(void) | |||
| @@ -77,11 +77,12 @@ void chiffre_xor_fichier(char *buf, int l) | |||
| #endif | |||
| #ifdef PLAYFAIR | |||
| char table_chiffre[NBO]; /* table des octets à chiffrer */ | |||
| char table_bool[NBO] = {0}; /* table pour noter le remplissage des octets */ | |||
| static char table_chiffre[NBO]; /* table des octets à chiffrer */ | |||
| static char table_bool[NBO] = {0}; /* table pour noter le remplissage des octets */ | |||
| #ifdef DEBUG | |||
| void Trace(void) // affiche la table de chiffrement | |||
| /* Fonction qui affiche la table de chiffrement. */ | |||
| static void Trace(void) | |||
| { | |||
| int i, j; | |||
| unsigned char c; | |||
| @@ -141,7 +142,7 @@ void init_table_chiffre(char *cle) /* on passe la clé en parametre */ | |||
| } | |||
| /* Fonction qui définit les coordonnées d'un caractère à partir de sa position dans la table */ | |||
| void coordCar(char C, int *l, int *c) | |||
| static void coordCar(char C, int *l, int *c) | |||
| { | |||
| int i; | |||
| @@ -152,7 +153,7 @@ void coordCar(char C, int *l, int *c) | |||
| } | |||
| /* Fonction qui retourne le caractère de la ligne l, colonne c */ | |||
| char carLC(int l, int c) | |||
| static char carLC(int l, int c) | |||
| { | |||
| return(table_bool[(l * LCM) + c]); | |||
| } | |||
| @@ -17,22 +17,17 @@ | |||
| /* ******** */ | |||
| #ifdef DEBUG | |||
| /* Fonction qui affiche la table de chiffrement. */ | |||
| void Trace(void); | |||
| #endif | |||
| #ifdef XOR_SIMPLE | |||
| /* Fonction de chiffrement avec xOR, en utilisant une clé fixe de 64 bits. */ | |||
| void chiffre_xor_simple(char *buf, int l); | |||
| extern void chiffre_xor_simple(char *buf, int l); | |||
| #endif | |||
| #ifdef XOR_FICHIER | |||
| #define LCLE 8192 // longueur de la clé : 8ko = 65536 bits, ATTENTION, doit être un multiple de 8*n | |||
| /* Fonction qui initialise la clé à partir d'un fichier externe. */ | |||
| int init_cle_xor(void); | |||
| extern int init_cle_xor(void); | |||
| /* Fonction de chiffrement avec xOR, en utilisant une clé externe provenant d'un fichier. */ | |||
| void chiffre_xor_fichier(char *buf, int l); | |||
| extern void chiffre_xor_fichier(char *buf, int l); | |||
| #endif | |||
| #ifdef PLAYFAIR | |||
| @@ -42,14 +37,10 @@ void chiffre_xor_fichier(char *buf, int l); | |||
| #define LCM 6 // Longueur du côté de la matrice | |||
| /* Fonction qui initialise la table de chiffrement. */ | |||
| void init_table_chiffre(char *cle); | |||
| /* Fonction qui définit les coordonnées d'un caractère à partir de sa position dans la table. */ | |||
| void coordCar(char C, int *l, int *c); | |||
| /* Fonction qui retourne le caractère de la ligne l, colonne c. */ | |||
| char carLC(int l, int c); | |||
| extern void init_table_chiffre(char *cle); | |||
| /* Fonction qui chiffre directement dans le buffer des données à chiffrer */ | |||
| void chiffre_playfair(char *B, int T); // B adresse du buf, T le nb d'octets | |||
| extern void chiffre_playfair(char *B, int T); // B adresse du buf, T le nb d'octets | |||
| /* Fonction inverse de chiffre_playfair, puisque cette fonction n'est pas involutive */ | |||
| void dechiffre_playfair(char *B, int T); // B adresse du buf, T le nb d'octets | |||
| extern void dechiffre_playfair(char *B, int T); // B adresse du buf, T le nb d'octets | |||
| #endif | |||
| #endif | |||
| @@ -21,11 +21,11 @@ | |||
| /* Variables globales */ | |||
| int RUN = 1; // booléen pour la boucle d'acceptation | |||
| int Chiff = 0; // valeur pour l'option de chiffrement, -1 pour local, 1 pour distant, 0 pour rien | |||
| in_port_t PORTL, PORTD; // ports distant et local au format du réseau ! | |||
| uint32_t ADDRD; // adresse distante au format réseau | |||
| int SidLoc, SidDist; // variables globales des deux taches de transfert | |||
| static int RUN = 1; // booléen pour la boucle d'acceptation | |||
| static int Chiff = 0; // valeur pour l'option de chiffrement, -1 pour local, 1 pour distant, 0 pour rien | |||
| static in_port_t PORTL, PORTD; // ports distant et local au format du réseau ! | |||
| static uint32_t ADDRD; // adresse distante au format réseau | |||
| static int SidLoc, SidDist; // variables globales des deux taches de transfert | |||
| /* Fonction qui agit en tant que handler pour signal() */ | |||
| @@ -138,7 +138,7 @@ void *fct_th(void *p) | |||
| chiffre_xor_fichier(buf, n); | |||
| #endif | |||
| #ifdef PLAYFAIR | |||
| chiffre_playfair(buf, n); | |||
| dechiffre_playfair(buf, n); | |||
| #endif | |||
| lb = htons((uint16_t) n); | |||
| write(SidDist, &lb, sizeof(lb)); // On envoie le nombre d'octets du paquet | |||
| @@ -207,7 +207,7 @@ int liaison(int fd) | |||
| chiffre_xor_fichier(buf, n); | |||
| #endif | |||
| #ifdef PLAYFAIR | |||
| chiffre_playfair(buf, n); | |||
| dechiffre_playfair(buf, n); | |||
| #endif | |||
| } | |||
| } else n = read(sid, buf, LBUF); | |||
| @@ -17,24 +17,24 @@ | |||
| #include <netdb.h> | |||
| /* Fonction qui traduit une adresse IPv4 en chaîne de caractères xxx.xxx.xxx.xxx */ | |||
| char *adip(uint32_t A); | |||
| extern char *adip(uint32_t A); | |||
| /* Fontion qui fabrique un IPv4 au format réseau */ | |||
| uint32_t makeip4(int a, int b, int c, int d); | |||
| extern uint32_t makeip4(int a, int b, int c, int d); | |||
| /* Fonction qui agit en tant que handler pour signal() */ | |||
| void interrupt(int S); | |||
| extern void interrupt(int S); | |||
| /* Fonction qui lit taille octets à la fois */ | |||
| int readNbc(int fd, char *buffer, int taille); | |||
| extern int readNbc(int fd, char *buffer, int taille); | |||
| /* Fonction du thread qui lit le port local et écrit vers le port distant */ | |||
| void *fct_th(void *p); | |||
| extern void *fct_th(void *p); | |||
| /* Création de la passerelle pour le client */ | |||
| int liaison(int fd); | |||
| extern int liaison(int fd); | |||
| /* Message d'aide pour l'utilisateur */ | |||
| void finerr(char *N, int err); | |||
| extern void finerr(char *N, int err); | |||
| #endif | |||