0

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
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • What is your question? Where are you stuck? – Rufus L Jan 18 '20 at 00:32
  • I stuck from converting my VB code of CryptRC4 to C# im just a beginner in C# Language – confidential account Jan 18 '20 at 00:33
  • This isn't a code writing service, though. Where *specifically* are you stuck? Questions like *"Please convert my code from one language to another"* are too broad. Are you having trouble with the function signature? The variable declarations? The `for` loops? Perhaps show your attempt so far, so we can help. – Rufus L Jan 18 '20 at 00:38

0 Answers0