- #include <iostream>
- #include <string>
- #include <fstream>
-
- using namespace std;
-
- string crypte(string x,int plus) {
- for(int i=0;i<(int)x.size();i++)
- {
- x[i]=x[i]+plus;
- }
- return(x);
- }
-
- string decrypte(string x,int moins) {
- for(int i=0;i<(int)x.size();i++)
- {
- x[i]=x[i]-moins;
- }
- return(x);
- }
-
-
- int main()
- {
- int choix;
- long cle;
- char fichier[128],fichiercible[128];
- string line,s,cs;
-
- cout << "\033[2J" << "1. Cryptage\n2. Decryptage\n";
- cin >> choix;
- switch(choix)
- {
- case 1:
- {
- cout << "\nEntrez la cle (uniquement des chiffres) : ";
- cin >> cle;
- cin.ignore();
- cout << "Fichier source : ";
- cin.getline(fichier, 128);
- cout << "Fichier cible : ";
- cin.getline(fichiercible, 128);
- cout << "Lecture du fichier...\n";
- ifstream fi(fichier);
- while(!fi.eof())
- {
- getline(fi, line);
- s += line+'\n';
- }
- fi.close();
- cout << "Cryptage...\n";
- cs=crypte(s, cle);
- cout << "Ecriture dans le fichier cible...\n";
- ofstream fo(fichiercible);
- fo << cs;
- fo.close();
- cout << "OK\n";
- }
- break;
- case 2:
- {
- cout << "\nEntrez la cle (uniquement des chiffre) : ";
- cin >> cle;
- cin.ignore();
- cout << "Fichier source : ";
- cin.getline(fichier, 128);
- cout << "Fichier cible : ";
- cin.getline(fichiercible, 128);
- cout << "Lecture du fichier...\n";
- ifstream fi(fichier);
- while(! fi.eof())
- {
- getline(fi, line);
- cs += line+'\n';
- }
- fi.close();
- cout << "Decryptage...\n";
- s=decrypte(cs, cle);
- cout << "Ecriture dans le fichier cible...\n";
- ofstream fo(fichiercible);
- fo << s;
- fo.close();
- cout << "OK\n";
- }
- break;
- default: break;
- }
- }
-
-
-
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
string crypte(string x,int plus) {
for(int i=0;i<(int)x.size();i++)
{
x[i]=x[i]+plus;
}
return(x);
}
string decrypte(string x,int moins) {
for(int i=0;i<(int)x.size();i++)
{
x[i]=x[i]-moins;
}
return(x);
}
int main()
{
int choix;
long cle;
char fichier[128],fichiercible[128];
string line,s,cs;
cout << "\033[2J" << "1. Cryptage\n2. Decryptage\n";
cin >> choix;
switch(choix)
{
case 1:
{
cout << "\nEntrez la cle (uniquement des chiffres) : ";
cin >> cle;
cin.ignore();
cout << "Fichier source : ";
cin.getline(fichier, 128);
cout << "Fichier cible : ";
cin.getline(fichiercible, 128);
cout << "Lecture du fichier...\n";
ifstream fi(fichier);
while(!fi.eof())
{
getline(fi, line);
s += line+'\n';
}
fi.close();
cout << "Cryptage...\n";
cs=crypte(s, cle);
cout << "Ecriture dans le fichier cible...\n";
ofstream fo(fichiercible);
fo << cs;
fo.close();
cout << "OK\n";
}
break;
case 2:
{
cout << "\nEntrez la cle (uniquement des chiffre) : ";
cin >> cle;
cin.ignore();
cout << "Fichier source : ";
cin.getline(fichier, 128);
cout << "Fichier cible : ";
cin.getline(fichiercible, 128);
cout << "Lecture du fichier...\n";
ifstream fi(fichier);
while(! fi.eof())
{
getline(fi, line);
cs += line+'\n';
}
fi.close();
cout << "Decryptage...\n";
s=decrypte(cs, cle);
cout << "Ecriture dans le fichier cible...\n";
ofstream fo(fichiercible);
fo << s;
fo.close();
cout << "OK\n";
}
break;
default: break;
}
}