The problem is that VB's
functions do not have a direct equivalent in C#. They work fine when you're dealing with characters whose ANSI code is less than
. Beyond that, they will diverge from the Unicode values that C# deals with.
In your example, the 13th character of the output from your VB code will be
). The same character from the C# code will be
. It's visually the same character
], but not the same codepoint.
If you can change your VB code to use
, then your C# output will match.
Otherwise, you'll need to add a reference to the
assembly, and use the VB functions:
private string cryptEntry(string s)
const string k = "§$=)%;:-:*(\"§%\"§=(";
string r = s.PadRight(15, ' ').Substring(0, 15);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < r.Length; i++)
sb.Append(Strings.Chr(Strings.Asc(r[i]) ^ Strings.Asc(k[i])));
} Strings.Asc Method (Microsoft.VisualBasic) | Microsoft Docs
Strings.Chr(Int32) Method (Microsoft.VisualBasic) | Microsoft Docs
The output of
will vary depending on the code-page of the computer on which your code runs. If there's any possibility of your code running on computers with different locales, then you can't guarantee that the output will match.