#include <fstream.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int conv(char a)
{
int n;
n=0;
while((char)n!=a)
n++;
return(n);
}
int main(int argc, char **argv)
{
char clef[255];
int lon;
int ok;
int enc;
ok=1;
if(argc<2)
{
cout << "Pour convertir un fichier il faut le faire glisser sur l'icone du programme dansl'explorateur. Vous pouver aussi le definir en tant que programme ouvrant un\ncertain type de fichier.\n";
ok=0;
}
if(ok==1)
{
cout << "Clef:";
lon=0;
cin.get(clef,255);
cout << "Encodage=1, decodage=2:";
cin >> enc;
if(enc!=2&&enc!=1)
{
cout << "Mauvais choix!\nLe fichier ne sera pas modifier.\n";
ok=0;
}
else
if(enc==2)
enc=-1;
if(ok==1)
{
lon=strlen(clef);
int fich;
fich=0;
while(fich<argc-1)
{
fich++;
cout << argv[fich];
char ch;
int v;
v=0;
int h;
h=0;
int r;
char fi[255]="c:/windows/temp/temp.txt";
ofstream fout(fi);
fout << "";
fout.close();
ifstream fin(argv[fich]);
if(fin) // existe déjà ?
{
while (fin.get(ch))
{
h=conv(clef[v]);
r=conv(ch)-h*enc;
if(r<255)
r=r+255;
if(r>255)
r=r-255;
fout.open(fi, ios::app);
fout << (char)(r);
fout.close();
v++;
if(v>=lon)
v=0;
}
fin.close();
fout.open(argv[fich]);
fin.open("c:\\windows\\temp\\temp.txt");
if(fin) // existe déjà ?
while(fin.get(ch))
{
fout << ch;
}
else
cout << "c:/windows/temp/temp.txt absent.";
fin.close();
fout.close();
cout << " OK\n";
}
else
cout << " Erreur.\n";
fin.close();
}
}
}
system("PAUSE");
return 0;
}