00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef VIGENERE_H
00023 #define VIGENERE_H
00024
00025 #include <iostream>
00026 #include <cstdlib>
00027
00028
00029 using namespace std;
00030
00037 class Vigenere : public Cryptage{
00038 public:
00039 Vigenere(){};
00040 void SetCle(string cle){
00041 mCle=cle;
00042 }
00043
00049 string Crypter(string msg) const{
00050 string cryptage=msg;
00051 int codeAsciiMsg, codeAsciiCle;
00052 for(int i=0; i<msg.length(); i++){
00053 codeAsciiMsg=msg[i];
00054 codeAsciiCle=mCle[i%mCle.length()];
00055 cryptage[i]=codeAsciiMsg+codeAsciiCle;
00056 if(cryptage[i]==0) cerr<<"CODE VAUT ZERO pour le caractère n°"<<i<<" en clair:"<<codeAsciiMsg<<" avec la clé valant "<<codeAsciiCle<<endl;
00057 }
00058 return cryptage;
00059 }
00065 string Decrypter(string msg) const{
00066 string cryptage=msg;
00067 int codeAsciiMsg, codeAsciiCle;
00068 for(int i=0; i<msg.length(); i++){
00069 codeAsciiMsg=msg[i];
00070 codeAsciiCle=mCle[i%mCle.length()];
00071 cryptage[i]=codeAsciiMsg-codeAsciiCle;
00072 }
00073 return cryptage;
00074 }
00075
00076 void Test(){
00077 Vigenere v;
00078 v.SetCle("testdeVigenere");
00079 cout<<"Cryptage de \"Test\""<<endl;
00080 cout<<v.Crypter("Test")<<endl;
00081 cout<<"Décryptage du cryptage de \"Test\""<<endl;
00082 cout<<v.Decrypter(v.Crypter("Test"))<<endl;
00083 }
00084 private:
00088 string mCle;
00089 };
00090
00091 #endif