I've solved the problem My compiler was messing with signed chars instead of unsigned. I used this :
Code:
void bsl()
{
if(a.u > 127)
{
a.u = a.u << 1;
a.u = a.u | 0x01;
}
else if(a.u < 128)
{
a.u = a.u << 1;
a.u = a.u & 0xFE;
}
}
Same for bsr(). And I've made
Code:
union char_or_unsigned { char s; unsigned char u;} a;
instead of signed / unsigned char. The encryptor function :
Code:
void encry(char* fileIN)
{
fin.open(fileIN, ios::binary);
if(!fin) cout << "fin.ERROR";
fout.open("temp.cry", ios::binary);
if(!fout) cout << "fout.ERROR";
while(fin.get(a.s))
{
a.s = a.s ^ key[x++];
if(strlen(key) == x) x = 0;
bsl();
fout << a.s;
}
fin.close();
fout.close();
}
The problem was in bsl and bsr : the two IFs were following. Only, sometimes the first IF would make the second true, and it would execute again. I simply needed to add "else" in front
Thanks for all the help.