Re: Get ASCII value for character when higher than 127
Oke, I've decided to leave the int values be for a while and am now
trying to XOR the string that I write to an output file, and then in
C# I do the same XOR to get the original string back.
But, again, this works fine for normal characters, but not for the
special ones. This whole encoding stuff is starting to driving me
nuts!!!
In C++ I use the following XOR function before writing the output to
text:
string XOR(string value,string key)
{
string retval(value);
unsigned int klen=key.length();
unsigned int vlen=value.length();
unsigned int k=0;
unsigned int v=0;
for(v;v<vlen;v++)
{
retval[v]=value[v]^key[k];
k=(++k<klen?k:0);
}
return retval;
}
Then, in C#, I've implemented my XOR function as follows:
private string XOR(string encrypted, string key)
{
string retval = "";
char[] encryptArray = encrypted.ToCharArray();
char[] keyArray = key.ToCharArray();
char currentChar;
int encryptedLen = encryptArray.Length -1;
int keyLen = keyArray.Length -1;
int k = 0;
for (int i = 0; i < encryptedLen; i++)
{
currentChar = Convert.ToChar(encryptArray[i] ^
keyArray[k]);
retval += currentChar.ToString();
if (k < keyLen)
{
k++;
}
else
{
k = 0;
}
}
return retval;
}
Anyone here with both C++ and C# knowledge who can tell me why this is
not working??
Maybe I should go back to the int values after all :-(
Sandra