I'm trying to encrypt a string in C#:
static public string Encrypt(char[] a)
{
for (int i = 0; i < a.Length; i++)
{
a[i] -= (char)(i + 1);
if (a[i] < '!')
{
a[i] += (char)(i + 20);
}
}
return new string(a);
}
Now, when I put in this string:
"Qui habite dans un ananas sous la mer?".
The encryption comes out as:
`Psf3c[[ak[3XT`d3d\3MYKWIZ3XSXU3L@?JAMR`
There's an unrecognizable character in there, after the @. I don't know how it got there, and I don't know why.
If I try to decrypt it (using this method:)
static public string Decrypt(char[] a)
{
for (int i = 0; i < a.Length; i++)
{
a[i] += (char)(i + 1);
if ((a[i] - 20) - i <= '!')
{
a[i] -= (char)(i + 20);
}
}
return new string(a);
}
This is the (incorrect) output:
Qui habite dans un ananas sous laamerx.
How do I allow the encryption routine to access unicode characters?