1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| #include <iostream>
#include <string>
#include <map>
#include <iterator>
#include <fstream>
#include <algorithm>
class ChiffrementSubst{
public:
ChiffrementSubst(const std::string& nomFichier):nom_fichier(nomFichier),tableauCopy()
{
std::ifstream fichier(nom_fichier);
std::istream_iterator<char,char> it(fichier);
std::istream_iterator<char,char>fin;
copy(it,fin,tableauCopy.begin());
}
char operator ()(char lettre)
{
std::map<char,char>::iterator trouve = tableauCopy.find(lettre);
if(trouve == tableauCopy.end())
{
std::cout<<"Le caractere n'est pas trouvable"<<std::endl;
}
else
{
lettre = trouve->second;
return lettre;
}
}
private:
std::string nom_fichier;
std::map<char,char>tableauCopy;
};
int main()
{
// Le message a crypter
std::string texte("BIENVENUE SUR LE MOOC C++ D'OCR !!");
// Demande de la cle a l'utilisateur
std::cout << "Quel fichier contenant la cle voulez-vous utiliser ? ";
std::string nomFichier;
std::cin >> nomFichier;
ChiffrementSubst foncteur(nomFichier);
std::string texte_crypte;
transform(texte.begin(),texte.end(),texte_crypte.begin(),foncteur());
std::cout<<texte_crypte<<std::endl;
return 0;
} |
Partager