I have special characters that i convert it by using this code.
public static string FromHex(string sText)
{
var bytes = StringToByteArray(sText);
var latinEncoding = Encoding.GetEncoding(1252);
var result = latinEncoding.GetString(bytes);
return result;
}
public static byte[] StringToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
and call for like this
string prFromHex = modEncryptText.FromHex("BAA37D40186D").ToString();
i got the results: º£}@\u0018m and i want it to convert into string with the keyword of "password" and the result should be "EVENTS". I want to convert my VB code into C# language here is my VB code.
Public Function CryptRC4(ByRef sText As String, ByRef sKey As String) As String
Dim baS(255) As Byte
Dim baK(255) As Byte
Dim bytSwap As Byte
Dim lI As Integer
Dim lJ As Integer
Dim lIdx As Integer
CryptRC4 = ""
For lIdx = 0 To 255
baS(lIdx) = lIdx
baK(lIdx) = Asc(Mid(sKey, 1 + (lIdx Mod Len(sKey)), 1))
Next
For lI = 0 To 255
lJ = (lJ + baS(lI) + baK(lI)) Mod 256
bytSwap = baS(lI)
baS(lI) = baS(lJ)
baS(lJ) = bytSwap
Next
lI = 0
lJ = 0
For lIdx = 1 To Len(sText)
lI = (lI + 1) Mod 256
lJ = (lJ + baS(lI)) Mod 256
bytSwap = baS(lI)
baS(lI) = baS(lJ)
baS(lJ) = bytSwap
CryptRC4 = CryptRC4 & Chr(pvCryptXor(baS((CInt(baS(lI)) + baS(lJ)) Mod 256), Asc(Mid(sText, lIdx, 1))))
Next
End Function
Private Function pvCryptXor(ByVal lI As Integer, ByVal lJ As Integer) As Integer
If lI = lJ Then
pvCryptXor = lJ
Else
pvCryptXor = lI Xor lJ
End If
End Function