Problème cryptage simple de fichier
Salut à tous!
Je vous explique mon problème: j'ai commencé une petit programme de cryptage tout simple (je débute...) seulement voila cela fonctionne nickel sur des fichiers texte mais sur des fichiers bitmap par exemple sans que j'arrive à comprendre pourquoi le cryptage ne s'effectue pas jusqu'au bout (à vrai dire il me manque à peu près 99,9% du fichier une fois decrypté :aie: )
Alors voila je vous met le code de ma classe cryptage si quelqu'un d'entre vous pourrai éclairer ma lanterne je lui serai très reconnaissant:D !
PS: je met toute la source mais le problême intervient pendant l'exécution de la méthode crypter()
Code:
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| class CryptageSimple
{
public:
CryptageSimple(char* cle, char* chemin1, char* chemin2)
{
keylen=strlen(cle);
key=new char[keylen] ;
strcpy(key, cle);
int len=strlen(chemin1);
path=new char[len];
strcpy(path,chemin1);
len=strlen(chemin2);
path2=new char[len];
strcpy(path2,chemin2);
};
bool crypter()
{
char line[1];
unsigned int a;
unsigned char b;
int i=0;
ifstream f(path);
ofstream ff(path2);
if(i>=keylen) i=0;
f.read( line, 1 ) ;
b=line[0];
a=(int)b;
a+=(int)key[i];
a=a%255;
b=a;
i++;
while(!f.eof())
{
ff<<b;
if(i>=keylen) i=0;
f.read( line, 1 ) ;
b=line[0];
a=(int)b;
a+=(int)key[i];
a=a%255;
b=a;
i++;
}
ff<<b;
cout<<"Opération effectuée";
return 0;
};
bool decrypter()
{
char line[1];
int a;
unsigned char b;
int i=0;
ifstream f(path);
ofstream ff(path2);
if(i>=keylen) i=0;
f.read( line, 1 ) ;
b=line[0];
a=(int)b;
a-=(int)key[i];
a=a%255;
b=(char)a;
i++;
while(!f.eof())
{
ff<<b;
if(i>=keylen) i=0;
f.read( line, 1 ) ;
b=line[0];
a=(int)b;
a-=(int)key[i];
a=a%255;
b=(char)a;
i++;
}
cout<<"Opération effectuée";
return 0;
};
private:
int keylen;
char* key;
char* path;
char* path2;
}; |
Voila merci d'avance à ceux qui pourrait m'aider...