Hi Galik,
Yes you are right. Sorry that I am not very clear.
The encryption algorithm works progressively, character by character.
So I will enter a whole string of text to encrypt, and a whole string of text as an encryption key.
However, the original encryption algorithm works progressively, char by char of the original string, and printf out the new encrypted output char by char.
I would like to just store the encrypted output somehow, be it string, c-string, ostringstream, etc.
As long as I can store it into something I can carry on with what I wish to do with the variable. Just printing it out char by char onto screen means I cannot carry on doing stuff with the encrypted text.
Hence, I tried to append it into a string, c-string and ostringstream. However, all 3 approaches gave me different values to the original algorithm.
1 2 3 4 5 6
|
unsigned char temp = plaintextStr[y] ^ rc4_output(); //1 failed attempt
unsigned int temp2 = plaintextStr[y] ^ rc4_output(); //also a failed attempt
printf("%02X", plaintextStr[y] ^ rc4_output()); //this should be the correct output
printf("%02X", temp); //wrong output
printf("%02X", temp2); //wrong output
|
As you can see, the original attempt simply printf it directly out to screen.
The other 2 failed attempts which I tried, either an unsigned char or an unsigned int, both gave me wrong output. I have also tried various int, signed int, char, char*, ostringstream, string, all are wrong.
I guess it has something to do with conversion of unsigned char or the displaying of hex characters.
Thanks in advance.