my mistake, my few mistakes.
first of all the code is infact C++, it has the .cpp extension, and uses C++ streams and functions for file management. sorry about that, I thought the code I posted was infact C, but just a different style of writing a C style cast (as I know most C/C++ compilers are lenient on code style).
secondly, b is declared as an int, not a char.
this is not your ordinary simple XOR encrypt routine, although it is still simple, it utilizes a different technique of adding ASCII values of each char in the input string and the key together. here it is, even though I am aware that this is the C forum, moderators please move this if you see fit, and I am sorry about this (this is the first time I've posted C++ in the C forum, simply because like I said I thought the section I was looking at was ordinary C code written in an odd style), here is the snippet I am interested in:
are the casts still unnecessary here even though the ASCII values of the characters from the file are added to the ASCII values of the characters in the key?
Here's how the encryption works. It takes the ASCII number for each character of
the key and of the file, and adds them together. Say the key is "patrick", then
to encrypt the line "isverycool" it would look like this:
The key simply repeats itself to accomodate encrypting a line that is longer than
Then, we do a bitwise XOR on the 2 chars with the logic that if you XOR 2 things,
then XOR them again you'll end up back where you started.
00100101 <-- Key
01010101 <-- Data
10001111 <-- Result
Now, let's place result against the key
00100101 <-- Key
10001111 <-- Encrypted data
01010101 <-- It matches our original data!!!
The result is a fairly complex encryption, which can be cracked, but not
without a lot of time and effort.
i = 0; // for whatever reason the program seems to crash without these lines
fsize = 0;
fin.get(a); // get the character to be encrypted
b = int(a); // store the ASCII value of a into b as an int value
b = b^key[i]; // our bitwise XOR
b += int(key[i]);
if (i < limit) i++; else i = 0;
a = char(b); // convert b back in an ASCII value
fout << a;
//cout << " ";
//cout << int(float(fsize)/float(f1size)*100) << "%";
//cout << fsize << "/" << f1size;
thank you in advance, and again, sorry for the mix up here, it won't happen again.