Professional Documents
Culture Documents
MOULAIRE Anthony
S2D
Apprendre
autrement :
CRYPTOGRAPHIE ET
PROGRAMMATION :
Chiffrement par
permutations
Objectifs :
Raliser un programme en C permettant de chiffrer un message
laide dun algorithme de chiffrement par permutations.
Proposer ensuite un algorithme ralisant une cryptanalyse de
ce moyen de chiffrement.
SOMMAIRE :
Introduction
I)
Introduction
Le chiffrement par permutation est un outil informatique en
langage C, qui est souvent utilis pour la cryptographie. Il
permet de transformer laide dune cl de chiffrement, des
informations ou signaux clairs en informations ou signaux
incomprhensibles pour des personnes nayant pas
connaissance de cette cl. La cryptographie permet de protger
la confidentialit des informations fournies dans le message
crypt.
I)
Prsentation :
Dans notre projet, nous devons raliser un programme en C,
qui permet de chiffrer un message, afin que le message ne
puisse pas tre compris par une personne extrieure au
programme.
Nous avons commenc par raliser un algorithme qui
demande un utilisateur dentrer un message, et qui lui
retourne ce mme message, crypt avec une cl de
chiffrement prdfinie.
Comme nous nous servons dune cl de chiffrement, nous
avons le choix entre la dfinir au dbut du programme, ou
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
int main(void)
{
char mot1[8];
// tableau o le mot donn par l'utilisateur est rang
char permu_tab[8];
// tableau o le mot permut est rang
char permu_tab2[8];
// tableau o le mot initial est rang
int matrice[7][7]={
// matrice permettant de permuter le mot
{0,0,1,0,0,0,0},//1
{0,0,0,0,1,0,0},//2
{1,0,0,0,0,0,0},//3
{0,0,0,1,0,0,0},//4
{0,0,0,0,0,1,0},//5
{0,1,0,0,0,0,0},//6
{0,0,0,0,0,0,1}};//7
int matrice1[7][7]={
// matrice permettant de retrouver le mot initial
{0,0,1,0,0,0,0},//1
{0,0,0,0,0,1,0},//6
{1,0,0,0,0,0,0},//3
{0,0,0,1,0,0,0},//4
{0,1,0,0,0,0,0},//2
{0,0,0,0,1,0,0},//5
{0,0,0,0,0,0,1}};//7
int k=0;
// rel permettant d'incrementer les tableaux o le mot est cod
int i=0;
// rel permettant de changer de ligne et de colonne dans la matrice
cout<<"Donner un mot de 7 lettres"<<endl;
cin>>mot1;
cout<<"Le nombre de lettres est "<<strlen(mot1)<<endl;
//strlen permet de savoir combien de lettres possde le mot donn par
l'utilisateur
while(k<(int)strlen(mot1))
{
permu_tab[k]=mot1[0]*matrice[0][k];
// initialise la premire case du tableau permu_tab par la mutiplication
entre la premire lettre du mot et le nombre prsent dans la matrice ligne
0 et colonne 0 de la matrice
i=1;
while(i<(int)strlen(mot1))
{
permu_tab[k]= permu_tab[k]+mot1[i]*matrice[i][k];
// incrmente le tableau permu_tab par la multiplication
entre les diffrentes lettres du mot et la matrice
i++;
// incrmentation du rel pour que nous changions de lettre dans le mot et
de colonne dans la matrice
}
k++;
// incrmentation du rel pour pouvoir changer de case dans le tableau o
le mot est permut ainsi que les lignes dans la matrice
}
permu_tab[k]='\0';
cout<< "Le mot permut est "<<permu_tab<<endl;
//return 0;
getch();
"<<permu_tab2<<endl;
#include<iostream>
#include<conio.h>
#include <string.h>
using namespace std;
int main(void)
{
char mot2[5];
// tableau o le mot donn par l'utilisateur est rang
char mot_permu[5];
char mot_permu1[5];
char mot_permu2[5];
char mot_permu3[5];
char mot_permu4[5];
char mot_permu5[5];
char mot_permu6[5];
char mot_permu7[5];
char mot_permu8[5];
char mot_permu9[5];
char mot_permu10[5];
char mot_permu11[5];
char mot_permu12[5];
char mot_permu13[5];
char mot_permu14[5];
char mot_permu15[5];
char mot_permu16[5];
char mot_permu17[5];
char mot_permu18[5];
char mot_permu19[5];
char mot_permu20[5];
char mot_permu21[5];
char mot_permu22[5];
char mot_permu23[5];
// 24 tableaux pour trouver le mot initial
// reprsentente les 24 matrices pour trouver le bon mot
int matrice[4][4]={//1
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1}};
int matrice1[4][4]={//2
{1,0,0,0},
{0,1,0,0},
{0,0,0,1},
{0,0,1,0}};
int matrice2[4][4]={//3
{1,0,0,0},
{0,0,1,0},
{0,1,0,0},
{0,0,0,1}};
int matrice3[4][4]={//4
{1,0,0,0},
{0,0,1,0},
{0,0,0,1},
{0,1,0,0}};
int matrice4[4][4]={//5
{1,0,0,0},
{0,0,0,1},
{0,1,0,0},
{0,0,1,0}};
int matrice5[4][4]={//6
{1,0,0,0},
{0,0,0,1},
{0,0,1,0},
{0,1,0,0}};
int matrice6[4][4]={//7
{0,1,0,0},
{1,0,0,0},
{0,0,1,0},
{0,0,0,1}};
int matrice7[4][4]={//8
{0,1,0,0},
{1,0,0,0},
{0,0,0,1},
{0,0,1,0}};
int matrice8[4][4]={//9
{0,1,0,0},
{0,0,1,0},
{1,0,0,0},
{0,0,0,1}};
int matrice9[4][4]={//10
{0,1,0,0},
{0,0,1,0},
{0,0,0,1},
{1,0,0,0}};
int matrice10[4][4]={//11
{0,1,0,0},
{0,0,0,1},
{1,0,0,0},
{0,0,1,0}};
int matrice11[4][4]={//12
{0,1,0,0},
{0,0,0,1},
{0,0,1,0},
{1,0,0,0}};
int matrice12[4][4]={//13
{0,0,1,0},
{1,0,0,0},
{0,1,0,0},
{0,0,0,1}};
int matrice13[4][4]={//14
{0,0,1,0},
{1,0,0,0},
{0,0,0,1},
{0,1,0,0}};
int matrice14[4][4]={//15
{0,0,1,0},
{0,1,0,0},
{1,0,0,0},
{0,0,0,1}};
int matrice15[4][4]={//16
{0,0,1,0},
{0,1,0,0},
{0,0,0,1},
{1,0,0,0}};
int matrice16[4][4]={//17
{0,0,1,0},
{0,0,0,1},
{1,0,0,0},
{0,1,0,0}};
int matrice17[4][4]={//18
{0,0,1,0},
{0,0,0,1},
{0,1,0,0},
{1,0,0,0}};
int matrice18[4][4]={//19
{0,0,0,1},
{1,0,0,0},
{0,1,0,0},
{0,0,1,0}};
int matrice19[4][4]={//20
{0,0,0,1},
{1,0,0,0},
{0,0,1,0},
{0,1,0,0}};
int matrice20[4][4]={//21
{0,0,0,1},
{0,1,0,0},
{1,0,0,0},
{0,0,1,0}};
int matrice21[4][4]={//22
{0,0,0,1},
{0,1,0,0},
{0,0,1,0},
{1,0,0,0}};
int matrice22[4][4]={//23
{0,0,0,1},
{0,0,1,0},
{1,0,0,0},
{0,1,0,0}};
int matrice23[4][4]={//24
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{0,0,0,1}};
int k=0;
// rel permettant d'incrmenter les tableaux o le mot est cod
int i=0;
// rel permettant de changer de ligne et de colonne dans la matrice
cout<<"Donner un mot de 4 lettres"<<endl;
cin>>mot2;
cout<<"Le nombre de lettres est "<<strlen(mot2)<<endl;
//strlen permet de savoir combien de lettre a le mot donn par
l'utilisateur
while(k<(int)strlen(mot2))
{
mot_permu[k]=mot2[0]*matrice[0][k];
// initialise la premire case du tableau permu_tab par la multiplication
entre la premire lettre du mot et le nombre prsent dans la matrice ligne
0 et colonne 0 de la matrice
i=1;
while(i<(int)strlen(mot2))
{
mot_permu[k]= mot_permu[k]+mot2[i]*matrice[i][k];
// incrmente le tableau permu_tab par la multiplication entre les
diffrentes lettres du mot et la matrice
i++;
// incrmentation du rel pour que nous changions de lettre dans le mot et
de colonne dans la matrice
}
k++;
// incrmentation du rel pour pouvoir changer de case dans le tableau o
le mot est permut ainsi que les lignes dans la matrice
}
mot_permu[k]='\0';
cout<< "La premire permutation est "<<mot_permu<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu1[k]=mot2[0]*matrice1[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu1[k]= mot_permu1[k]+mot2[i]*matrice1[i][k];
i++;
}
k++;
}
mot_permu1[k]='\0';
cout<< "La deuxime permutation est
"<<mot_permu1<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu2[k]=mot2[0]*matrice2[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu2[k]= mot_permu2[k]+mot2[i]*matrice2[i][k];
i++;
}
k++;
}
mot_permu2[k]='\0';
cout<< "La troisime permutation est
"<<mot_permu2<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu3[k]=mot2[0]*matrice3[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu3[k]= mot_permu3[k]+mot2[i]*matrice3[i][k];
i++;
}
k++;
}
mot_permu3[k]='\0';
cout<< "La quatrime permutation est
"<<mot_permu3<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu4[k]=mot2[0]*matrice4[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu4[k]= mot_permu4[k]+mot2[i]*matrice4[i][k];
i++;
}
k++;
}
mot_permu4[k]='\0';
cout<< "La cinquime permutation est
"<<mot_permu4<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu5[k]=mot2[0]*matrice5[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu5[k]= mot_permu5[k]+mot2[i]*matrice5[i][k];
i++;
}
k++;
}
mot_permu5[k]='\0';
cout<< "La sixime permutation est
"<<mot_permu5<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu6[k]=mot2[0]*matrice6[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu6[k]= mot_permu6[k]+mot2[i]*matrice6[i][k];
i++;
}
k++;
}
mot_permu6[k]='\0';
cout<< "La septime permutation est
"<<mot_permu6<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu7[k]=mot2[0]*matrice7[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu7[k]= mot_permu7[k]+mot2[i]*matrice7[i][k];
i++;
}
k++;
}
mot_permu7[k]='\0';
cout<< "La huitime permutation est
"<<mot_permu7<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu8[k]=mot2[0]*matrice8[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu8[k]= mot_permu8[k]+mot2[i]*matrice8[i][k];
i++;
}
k++;
}
mot_permu8[k]='\0';
cout<< "La neuvime permutation est
"<<mot_permu8<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu9[k]=mot2[0]*matrice9[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu9[k]= mot_permu9[k]+mot2[i]*matrice9[i][k];
i++;
}
k++;
}
mot_permu9[k]='\0';
cout<< "La dixime permutation est
"<<mot_permu9<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu10[k]=mot2[0]*matrice10[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu10[k]= mot_permu10[k]+mot2[i]*matrice10[i][k];
i++;
}
k++;
}
mot_permu10[k]='\0';
cout<< "La onzime permutation est
"<<mot_permu10<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu11[k]=mot2[0]*matrice11[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu11[k]= mot_permu11[k]+mot2[i]*matrice11[i][k];
i++;
}
k++;
}
mot_permu11[k]='\0';
cout<< "La douzime permutation est
"<<mot_permu11<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu12[k]=mot2[0]*matrice12[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu12[k]= mot_permu12[k]+mot2[i]*matrice12[i][k];
i++;
}
k++;
}
mot_permu12[k]='\0';
cout<< "La treizime permutation est
"<<mot_permu12<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu13[k]=mot2[0]*matrice13[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu13[k]= mot_permu13[k]+mot2[i]*matrice13[i][k];
i++;
}
k++;
}
mot_permu13[k]='\0';
cout<< "La quartozime permutation est
"<<mot_permu13<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu14[k]=mot2[0]*matrice14[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu14[k]= mot_permu14[k]+mot2[i]*matrice14[i][k];
i++;
}
k++;
}
mot_permu14[k]='\0';
cout<< "La quinzime permutation est
"<<mot_permu14<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu15[k]=mot2[0]*matrice15[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu15[k]= mot_permu15[k]+mot2[i]*matrice15[i][k];
i++;
}
k++;
}
mot_permu15[k]='\0';
cout<< "La seizime permutation est
"<<mot_permu15<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu16[k]=mot2[0]*matrice16[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu16[k]= mot_permu16[k]+mot2[i]*matrice16[i][k];
i++;
}
k++;
}
mot_permu16[k]='\0';
cout<< "La dix-septime permutation est
"<<mot_permu16<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu17[k]=mot2[0]*matrice17[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu17[k]= mot_permu17[k]+mot2[i]*matrice17[i][k];
i++;
}
k++;
}
mot_permu17[k]='\0';
cout<< "La dix-huitime permutation est
"<<mot_permu17<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu18[k]=mot2[0]*matrice18[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu18[k]= mot_permu18[k]+mot2[i]*matrice18[i][k];
i++;
}
k++;
}
mot_permu18[k]='\0';
cout<< "La dix-neuvime permutation est
"<<mot_permu18<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu19[k]=mot2[0]*matrice19[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu19[k]= mot_permu19[k]+mot2[i]*matrice19[i][k];
i++;
}
k++;
}
mot_permu19[k]='\0';
cout<< "La vingtime permutation est
"<<mot_permu19<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu20[k]=mot2[0]*matrice20[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu20[k]= mot_permu20[k]+mot2[i]*matrice20[i][k];
i++;
}
k++;
}
mot_permu20[k]='\0';
cout<< "La vingt et unime permutation est
"<<mot_permu20<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu21[k]=mot2[0]*matrice21[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu21[k]= mot_permu21[k]+mot2[i]*matrice21[i][k];
i++;
}
k++;
}
mot_permu21[k]='\0';
cout<< "La vingt deuxime permutation est
"<<mot_permu21<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu22[k]=mot2[0]*matrice22[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu22[k]= mot_permu22[k]+mot2[i]*matrice22[i][k];
i++;
}
k++;
}
mot_permu22[k]='\0';
cout<< "La vingt troisime permutation est
"<<mot_permu22<<endl;
i=0;
k=0;
while(k<(int)strlen(mot2))
{
mot_permu23[k]=mot2[0]*matrice23[0][k];
i=1;
while(i<(int)strlen(mot2))
{
mot_permu23[k]= mot_permu23[k]+mot2[i]*matrice23[i][k];
i++;
}
k++;
}
mot_permu23[k]='\0';
cout<< "La dernire permutation est
"<<mot_permu23<<endl;
getch();
}
Conclusion:
On peut conclure que ses programmes nous ont permis
damliorer notre niveau en Informatique Industriel, mais
surtout lutilisation du langage C++.
Pour raliser ses programmes, nous avons d effectuer
diffrentes recherches, comme pour lutilisation et la
dclaration dune matrice en langage C++. Ce projet nous a
aussi permis dapprendre travailler en quipe, et de nous
mettre dans des conditions relles de travail. Llaboration de
ce projet nous a permis de transformer les connaissances
thoriques apprises en cours en expriences pratiques.
Nous avons appris aussi grer la rpartition des tches dans
ce projet, afin doptimiser au maximum notre temps de travail.
Nous avons donc apprci ce projet, qui est pour les lves, une
faon intressante dapprendre et dutiliser la thorie vue en
cours.