Hello,
I'm writing a (very very bad) encryption program. I wanted to use bitwrap in my program, but for some reason, it's not working, and I can't quite see where.
Code:// from encrypt.h
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))
{
a = a ^ key[x++];
if(strlen(key) == x) x = 0;
bsl();
fout << a;
}
fin.close();
fout.close();
}
Code:// bsl() - bitshift left. Code as follows.
void bsl()
{
if(a > 127)
{
a = a << 1;
a = a ^ 0x01;
}
if(a < 128)
{
a = a << 1;
a = a & 0xFE;
}
}
void bsr()
{
if(((int)a % 2) == 0)
{
a = a >> 1;
a = a & 0x7F;
}
if(((int)a % 2) == 1)
{
a = a >> 1;
a = a ^ 0x80;
}
}
Obviously, the decrypting function bitshifts right before XORing. If I try to encrypt / decrypt a simple text file containing ABCDE, I realise that only B and D get decrypted correctly. I'm guessing this means I've got something wrong with ODD-numbered ASCII characters... But I can't see what.
Thanks for your help.