Private Const HARD_KEY = &H37
Private Function Encrypt(sValue, sKey)
    Dim intLen
    Dim sTempValue
    Dim sTempKey
    Dim sRValue
    Dim sChar
    sChar = 0
    sTempValue = sValue
    sTempKey = Trim(sKey)
    sRValue = ""
    Dim intX, intY
    For intX = 1 To Len(sTempValue)
        sChar = CInt(Asc(Mid(sTempValue, intX, 1)))
        For intY = 1 To Len(sTempKey)
            sChar = sChar Xor CInt(Asc(Mid(sTempKey, intY, 1))) Xor HARD_KEY
        Next
        sRValue = sRValue & Trim(Chr(sChar))
    Next
    Encrypt = sRValue
End Function有没有懂C#的高手帮忙把上面的ASP代码转成c# asp.net的代码 下面是我转的 觉得不对,有没有高手能帮忙找错的int HARD_KEY = Convert.ToInt32("37", 16);
private string Encrypt(string sValue, string sKey)
        {
            string sTempValue = sValue;
            string sTempKey = sKey.Trim();
            string sRValue = "";
            int sChar = 0;
            for(int x = 1;x < sTempValue.Length;x++ )
            {
                sChar = Microsoft.VisualBasic.Strings.Asc(sTempValue.Substring(x, 1));
                for(int y = 1;y <sTempKey.Length;y ++)
                {
                    int asc = Microsoft.VisualBasic.Strings.Asc(sTempValue.Substring(y, 1));
                    sChar = asc | HARD_KEY;
                }
                sRValue = sRValue + Microsoft.VisualBasic.Strings.Chr(sChar).ToString(); 
            }
            listBox3.Items.Add(sRValue);
            return sRValue;   
        }

解决方案 »

  1.   

    try->
            int HARD_KEY = Convert.ToInt32("37", 16);
            private string Encrypt(string sValue, string sKey)
            {
                string sTempValue = sValue;
                string sTempKey = sKey.Trim();
                string sRValue = "";
                int sChar = 0;
                for (int x = 1; x < sTempValue.Length; x++)
                {
                    sChar = Convert.ToInt32(sTempValue.Substring(x, 1));
                    for (int y = 1; y < sTempKey.Length; y++)
                    {
                        int asc = Convert.ToInt32(sTempValue.Substring(y, 1));
                        sChar = asc | HARD_KEY;
                    }
                    sRValue = sRValue + Convert.ToChar(sChar).ToString();
                }
                listBox3.Items.Add(sRValue);
                return sRValue;
            }
      

  2.   

    楼上的不对~string.Substring(int index,int len)是取index起的len个字符,但不包括index位字符,vb的不一样,是包括自身的,所以要减去1,还有没有高手帮帮忙
      

  3.   

    我的修改版本,高手能不能指点一下,感觉还是有问题 int HARD_KEY = Convert.ToInt32("37", 16);private string Encrypt(string sValue, string sKey)
            {
                string sTempValue = sValue;
                string sTempKey = sKey.Trim();
                string sRValue = "";
                int sChar = 0;
                for (int x = 1; x <= sTempValue.Length; x++)
                {
                    sChar = Microsoft.VisualBasic.Strings.Asc(sTempValue.Substring(x - 1, 1));
                    for (int y = 1; y <= sTempKey.Length; y++)
                    {
                        int asc = Microsoft.VisualBasic.Strings.Asc(sTempKey.Substring(y - 1, 1));
                        sChar = sChar ^ asc ^ HARD_KEY;
                        listBox3.Items.Add(sRValue + ";  " + asc + ";  " + sChar.ToString());
                    }
                    sRValue = sRValue + Microsoft.VisualBasic.Strings.Chr(sChar).ToString();            }            return sRValue;
            }
      

  4.   

    可以的~修改成:
    可还是不正确
    private string Encrypt(string sValue, string sKey)
            {
                string sTempValue = sValue;
                string sTempKey = sKey.Trim();
                string sRValue = "";
                int sChar = 0;
                for (int x = 0; x < sTempValue.Length; x++)
                {
                    sChar = Microsoft.VisualBasic.Strings.Asc(sTempValue.Substring(x , 1));
                    for (int y = 0; y < sTempKey.Length; y++)
                    {
                        int asc = Microsoft.VisualBasic.Strings.Asc(sTempKey.Substring(y, 1));
                        sChar = sChar ^ asc ^ HARD_KEY;
                    }
                    sRValue = sRValue + Microsoft.VisualBasic.Strings.Chr(sChar).ToString();
                }
                return sRValue;
            }
      

  5.   

    下面是用 vs2003 的 vb6 代码升级工具转换出来的,自己换成 C# 应该问题不大了吧?    Private Const HARD_KEY As Short = &H37S
        Private Function Encrypt(ByRef sValue As Object, ByRef sKey As Object) As Object
            Dim intLen As Object
            Dim sTempValue As Object
            Dim sTempKey As Object
            Dim sRValue As Object
            Dim sChar As Object
            'UPGRADE_WARNING: 未能解析对象 sChar 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
            sChar = 0
            'UPGRADE_WARNING: 未能解析对象 sValue 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
            'UPGRADE_WARNING: 未能解析对象 sTempValue 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
            sTempValue = sValue
            'UPGRADE_WARNING: 未能解析对象 sKey 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
            'UPGRADE_WARNING: 未能解析对象 sTempKey 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
            sTempKey = Trim(sKey)
            'UPGRADE_WARNING: 未能解析对象 sRValue 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
            sRValue = ""
            Dim intX, intY As Object
            For intX = 1 To Len(sTempValue)
                'UPGRADE_WARNING: 未能解析对象 intX 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
                'UPGRADE_WARNING: 未能解析对象 sTempValue 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
                'UPGRADE_WARNING: 未能解析对象 sChar 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
                sChar = CShort(Asc(Mid(sTempValue, intX, 1)))
                For intY = 1 To Len(sTempKey)
                    'UPGRADE_WARNING: 未能解析对象 intY 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
                    'UPGRADE_WARNING: 未能解析对象 sTempKey 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
                    'UPGRADE_WARNING: 未能解析对象 sChar 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
                    sChar = sChar Xor CShort(Asc(Mid(sTempKey, intY, 1))) Xor HARD_KEY
                Next
                'UPGRADE_WARNING: 未能解析对象 sChar 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
                'UPGRADE_WARNING: 未能解析对象 sRValue 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
                sRValue = sRValue & Trim(Chr(sChar))
            Next
            'UPGRADE_WARNING: 未能解析对象 sRValue 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
            'UPGRADE_WARNING: 未能解析对象 Encrypt 的默认属性。 单击以获得更多信息:“ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"”
            Encrypt = sRValue
        End Function
      

  6.   

    另外,VB中Chr(int) 这个函数在C#中用什么代替呀
      

  7.   

    初步估计是这样子的,另外HARD_KEY的数据类型是啥    private string Encrypt(string sValue, string sKey)
        {
            //Dim intLen        string sRValue = string.Empty;
            char sChar;
            //sChar = 0
            string sTempValue = sValue;
            string sTempKey = sKey.Trim();        foreach (char x in sTempValue)
            {
                sChar = x;
                foreach (char y in sTempKey)
                {
                    int asc = Convert.ToInt32(y);
                    sChar = (char)asc | HARD_KEY;
                }
                sRValue = sRValue + sChar.ToString();
            }
            listBox3.Items.Add(sRValue);
            return sRValue;
        }
      

  8.   

    前面的问题都解决了 &H是VB里十六进制的起始符号 就和c#里的0x一样.谢谢大家