#include #include #include #include #include //Prototype des fonctions void InitTabRef(int **tabref); void AffichTabRef(int **tabref); void RempliTabrefAlea (int **tabref); void RempliTabrefNonAlea (int **tabref); int main() { char choix; int i; int **tabref; //Allocation du tableau de référence; tabref=(int**)malloc(26*sizeof(int)); for(i=0;i<26;i++) tabref[i]=(int*)malloc(5*sizeof(int)); //Initialisation du tableau InitTabRef(&tabref[0]); do { //Menu de choix de la methodde de remplissage du tableau printf("\n\t\tBienvenue dans ce programme de cryptage !"); printf("\n\n\tVoulez vous remplir aleatoirement le tableau de reference ?"); printf("\n\tTapez 0 pour oui, 1 pour non\n"); printf("\tChoix : "); gets (&choix); system("cls"); }while(choix != '0' && choix != '1'); if(choix=='0') { RempliTabrefAlea(&tabref[0]); }else { RempliTabrefNonAlea (&tabref[0]); } do { system("cls"); if(choix == '1') { printf("\n\t\tVous avez choisi un remplissage manuel : \n"); }else { printf("\n\t\tVous avez choisi un remplissage automatique : \n"); } //Affichage du tableau printf("\n\t\tVoulez vous afficher le tableau de references ? "); printf("\n\n\t\tTapez 0 pour oui, 1 pour non"); printf("\n\t\tChoix : "); gets(&choix); }while(choix != '0' && choix != '1'); if(choix == '0') { AffichTabRef(&tabref[0]); } return 0; } /* On initialise le tableau en lui mettant le code ascii des characteres correspondants aux indices si on est dans la colone d'indice 0, sinon on initialise les postes a 0; */ void InitTabRef(int **tabref)//Fonction d'initialisation { int i,j; int ascii=97; for(i=0;i<26;i++) { for(j=0;j<5;j++) { if(j==0) { tabref[i][j]=ascii; ascii++; }else { tabref[i][j]=0; } } } } /* Fonction d'affichagge ou l'on affichera en '%c' si l'on est sur des codes ASCII ou bien en '%d' si l'on est sur des numéros */ void AffichTabRef(int **tabref)//Fonction d'affichage { int i, j; printf("\n\t\t\t"); for(i=0;i<26;i++) { for(j=0;j<5;j++) { if(j==0) { printf("|%c|", tabref[i][j]); }else { printf("|%d|", tabref[i][j]); } } printf("\n\t\t\t"); } } /* Fonction de remplissage de tableau par saisie, si un zero est saisi, on passe a la ligne supérieure, le zero signifie fin de code pour ce charactère */ void RempliTabrefNonAlea (int **tabref) { int i, j, k, compteur=0, compt=0; int *tabcompare; for(i=0;i<26;i++) for(j=1;j<5;j++) { system("cls"); printf("\n\t\t( 0 signifie fin de saisie pour ce charactere ! )"); printf("\n\t\tLigne %d, colone %d : ", i, j); scanf("%d", &tabref[i][j]); if(tabref[i][j]==0 && j==1) { printf("\n\t! Vous etes a l'indice 1, un charactere doit au moins avoir un code !\n\n\t"); system("pause"); i--; break; } if(tabref[i][j]==0) { break; } if(i==0 && j==1) { tabcompare=(int*)malloc(1*sizeof(int)); tabcompare[compteur]=tabref[i][j]; } else { compteur++; tabcompare=realloc(tabcompare,1*sizeof(int)); tabcompare[compteur]=tabref[i][j]; compt=0; for(k=0;k