I have a string that gets encrypted using VB6 and gets sucessfully decrypted using VB6 in other places. However, when I try to decrypt the string in C# I can get the letters to decrypt fine, but numbers and symbols dont. The code follows:
VB6 Encrypt:
Public Function SimpleEncode(sInputString) As String
Dim sOutputString As String
Dim iStringIndex As Integer
Dim iStringLength As Integer
Dim sCurChar As String
Dim sRandomChar As String
On Error GoTo SimpleEncode_Error
Randomize
iStringLength = Len(sInputString)
For iStringIndex = 1 To iStringLength
sCurChar = Mid(sInputString, iStringIndex, 1)
sOutputString = sOutputString & Chr((Asc(sCurChar) + 100) Mod 256) & Chr(Int(256 * Rnd))
Next
SimpleEncode = sOutputString
On Error GoTo 0
Exit Function
SimpleEncode_Error:
Call ErrHandler(DoLogging, "Error " & Err.Number & " (" & Err.Description & ") in procedure SimpleEncode of Module ModGlobalProcs")
End Function
VB6 Decrypt:
Public Function SimpleDecode(sInputString) As String
Dim iStringIndex As Integer
Dim iStringLength As Integer
Dim sCurChar As String
Dim sRandomChar As String
Dim sOutputString As String
On Error GoTo SimpleDecode_Error
iStringLength = Len(sInputString)
For iStringIndex = 1 To iStringLength
If (iStringIndex Mod 2 = 1) Then ' only process even characters
sCurChar = Mid(sInputString, iStringIndex, 1)
sOutputString = sOutputString & Chr(Abs(Asc(sCurChar) - 100) Mod 256)
End If
Next
SimpleDecode = sOutputString
On Error GoTo 0
Exit Function
SimpleDecode_Error:
Call ErrHandler(DoLogging, "Error " & Err.Number & " (" & Err.Description & ") in procedure SimpleDecode of Module ModGlobalProcs")
End Function
C# Decrypt:
public static string DecodePassword(string sInputString)
{
int iStringIndex, iStringLength;
string sCurChar;
string sOutputString = "";
iStringLength = sInputString.Length;
for(iStringIndex = 0; iStringIndex < iStringLength; iStringIndex++)
{
if(iStringIndex % 2 == 0)
{
sCurChar = sInputString.Substring(iStringIndex, 1);
sOutputString = sOutputString + (Char)(Math.Abs((int)sCurChar[0] - 100) % 256);
}
}
return sOutputString;
}
Does anyone know why I cannot get this to work?