这个代码在VB网中

时间:2012-06-20 09:16:09

标签: c# vb.net encryption reflector decompiler

我已经用反射器

反编译了一个vb.net应用程序

使用此方法加密所有字符串:

Public Shared Function smethod_0(ByVal string_0 As String) As String
    Dim length As Integer = string_0.Length
    Dim chArray As Char() = New Char(length  - 1) {}
    Dim i As Integer
    For i = 0 To chArray.Length - 1
        Dim ch As Char = string_0.Chars(i)
        Dim num3 As Byte = CByte((ch Xor (length - i)))
        Dim num4 As Byte = CByte(((ch >> 8) Xor i))
        chArray(i) = DirectCast(((num4 << 8) Or num3), Char)
    Next i
    Return String.Intern(New String(chArray))
End Function

此方法接收如下输入字符串:

"j" & ChrW(354) & ChrW(623) & ChrW(868)

并返回一个可读的字符串。

如何在vb.net或c#中转换此代码?

Vb.net编译器抱怨此代码不正确,因为没有为char / int组合定义xor。

2 个答案:

答案 0 :(得分:0)

C#版本(仅出于教育原因 - 保留尽可能相似的代码):

public static string encrypt(string s)
{
    int length = s.Length, i = 0;
    char[] chArray = new char[length];
    byte b1, b2;
    char ch;
    for (i = 0; i <= chArray.Length - 1; i++)
    {
        ch = s[i];
        b1 = Convert.ToByte((ch ^ (length - i)));
        b2 = Convert.ToByte(((ch >> 8) ^ i));
        chArray[i] = (char)((b2 << 8) | b1);
    }
    return string.Intern(new string(chArray));
}

答案 1 :(得分:0)

我已经以这种方式解决了:

    public static string encrypt(string string_0)
    {
        int length = string_0.Length;
        char[] chArray = new char[length];
        for (int i = 0; i < chArray.Length; i++)
        {
            char ch = string_0[i];
            byte num3 = (byte)(ch ^ (length - i));
            byte num4 = (byte)((ch >> 8) ^ i);
            chArray[i] = (char)((num4 << 8) | num3);
        }

        File.AppendAllText("decript.txt", Environment.NewLine + string_0 + "  =  " + string.Intern(new string(chArray)));

return string.Intern(new string(chArray));

    }

感谢您的帮助