Quote Originally Posted by master5001 View Post
ffffffc2 is unsigned... It sounds like underflow, but I am not seeing any operation that would cause an underflow.

Code:
cyphertext += plaintext.at(i) ^ (S.at((S.at(j) + S.at(k)) % 256));
That line looks dubiously like the culprit. But I am compilerless at the moment, so yeah...
Well, the math is being done correctly. That is, the xor operation is providing the correct results. So, for example, when it's time to encrypt the '.', you have:
Code:
cyphertext += "." ^ 236;
            =  46 ^ 236
            = 194
That (unsigned) 194 is being stored in cyphertext as the signed int (char? wchar?) -62. This is what I don't know how to fix. I've tried substituting basic_string<unsigned char> for string, but that just breaks everything (like getline(), which I guess I don't know how to implement with basic_string<>).

I could rewrite the entire thing with c-style string, I suppose, and I imagine it would work without a hitch, but that defeats the purpose.