Vigenere.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Pierre Schmitt, Ludovic Giacomello, Nhi Ly   *
00003  *      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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

Generated on Wed Jan 2 14:01:42 2008 for Pacman by  doxygen 1.5.1