Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将此函数从VB转换为c#_C#_Vb.net - Fatal编程技术网

将此函数从VB转换为c#

将此函数从VB转换为c#,c#,vb.net,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(

我一直在拼命想把这个经典的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-sharp方法:

    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;
    }
公共静态字符串解密1(字符串s)
{
字符串函数returnvalue=null;
if(string.IsNullOrEmpty)
{
functionReturnValue=“”;
}
其他的
{
字符串r=null;
int ch=null;
对于(int i=0;i

您可以尝试在线转换器


以下是其中之一:

此示例适用于您的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);
    }
公共静态字符串解密1(字符串s)
{
if(string.IsNullOrEmpty)
返回字符串。空;
字符串r=null;

对于(int i=1;我试过在线转换器吗?s的数据类型是什么?相当蹩脚的密码告诉我们到目前为止你有什么,我们也许能把它分类。把函数分解成几个部分。谷歌如何在C#中做每个特定的部分。如何测试空值,如何测试字符串的长度,如何循环,如何获得子字符串,等等。把这些部分放到back together.&H是c#中的0x,十六进制指示符。可能没有任何转换器足够聪明来解决这个问题。是的,上面的代码看起来就像我从转换器中得到的代码。这里进行了非常奇怪的隐式转换,这并不像乍看起来那么简单。xor很好;^operatorWell,我实际上编写了它by hand..你能告诉我函数需要什么类型的字符串/数据吗?它看起来像是十六进制格式的东西。@vendettamit-0B031D00180003030A07应该解密到helloworld@MikeMorehead不用担心。请随意将答案标记为有用。:-)