Was trying to convert a code from VB to C#, see VB code below
Dim StrCount As Int16
Dim str1, str2, EncryptedStr As String
EncryptedStr = String.Empty
theString = "Test@1234"
For StrCount = 1 To Len(theString)
str1 = Asc(Mid(theString, StrCount, 1)) - 1
str2 = str1 + Asc(Mid(StrCount, 1))
EncryptedStr = EncryptedStr + Chr(str2)
Next
Converted C# code
string EncryptedStr = string.Empty;
Encoding encode1 = Encoding.ASCII;
Byte[] encodedBytes = encode1.GetBytes("Test@1234");
for (int count = 0; count < encodedBytes.Length; count++)
{
int str1 = encodedBytes[count] - 1;
Encoding encode2 = Encoding.ASCII;
Byte[] encodedBytes1 = encode2.GetBytes((count + 1).ToString());
int str2 = str1 + (int)encodedBytes1[0];
EncryptedStr += Convert.ToChar(str2);
}
Its working fine, but the problem i am facing is the encrypted password is different in VB & C#
I tried encrypting a string "Test@1234", the encrypted result was
VB: „–¥§tfhjl
C#: ¥§tfhjl
I debug and noticed that in C# Convert.ToChar(132) & Convert.ToChar(150) is giving empty value.
Can anybody explain, what is going wrong here