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

.



Relevant Pages

  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • RE: Controling Modal Dialogs (Solution)
    ... doesn't return until the 'modal' browser returns. ... string varOptions) ... public void DocumentComplete ... int rc = winDisp.Invoke(rgDispId, ref guid, 0, ...
    (microsoft.public.inetsdk.programming.webbrowser_ctl)
  • Gcc compatible header file
    ... A string collection is a table of zero terminated strings that will grow ... typedef struct _StringCollection StringCollection; ... int; ... bool; ...
    (comp.lang.c)
  • Kernighan and Pikes "Beautiful" Code
    ... conformant string. ... int repeats, reps; ... ref satisfierLength); ...
    (comp.programming)
  • Re: FTP CD command
    ... public const int GENERIC_WRITE = 0x40000000; ... string lpszProxyName, ... public static extern IntPtr InternetConnect ( ... public static extern bool FtpGetCurrentDirectory ( ...
    (microsoft.public.dotnet.languages.vb)

Loading