将此函数从 VB 转换为 c#

  • 本文关键字:转换 VB 函数 c# vb.net
  • 更新时间 :
  • 英文 :


我一直在试图将这个经典的asp(vb(转换为 asp.net C#,但没有运气。

Function Decrypt1(s)
    if isnull(s) then
    Decrypt1 = ""
    else
    Dim r, i, ch
    For i = 1 To Len(s)/2
        ch = "&H" & Mid(s, (i-1)*2+1, 2)
        ch = ch Xor 111
        r = r & Chr(ch)
    Next
    Decrypt1 = strReverse(r)
    end if
End Function

有接受者吗?

提前感谢!

编辑 - "0B031D00180003030A07"应解密为"helloworld">

已更新

以下是解密字符串的 c 尖锐方法:

    public static string Decrypt1(string s)
    {
        string functionReturnValue = null;
        if (string.IsNullOrEmpty(s))
        {
            functionReturnValue = "";
        }
        else
        {
            string r = null;
            int ch = null;
            for (int i = 0; i < s.Length / 2; i++)
            {
                ch = int.Parse(s.Substring((i) * 2, 2), NumberStyles.AllowHexSpecifier);
                ch = ch ^ 111;
                r = r + (char)(ch);
            }
            var charArray = r.ToCharArray();
            Array.Reverse(charArray);
            functionReturnValue = new string(charArray);
        }
        return functionReturnValue;
    }

在网络小提琴上尝试一下

您可以尝试在线转换器。

这是其中之一:http://converter.telerik.com/

这个适用于你的helloworld示例:

    public static string Decrypt1(string s)
    {
        if (string.IsNullOrEmpty(s))
            return string.Empty;
        string r = null;
        for (int i = 1; i <= s.Length / 2; i++)
        {
            var ch = Convert.ToUInt32(s.Substring((i - 1) * 2, 2), 16);
            ch = ch ^ 111;
            r = r + (char)(ch);
        }
        var charArray = r.ToCharArray();
        Array.Reverse(charArray);
        return new string(charArray);
    }

最新更新