读书人

vb代码转ASP.NET C#代码~ 急求

发布时间: 2012-02-11 09:51:35 作者: rapoo

vb代码转ASP.NET C#代码~ 急求 高手指点
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;
}

[解决办法]
try->

C# code
        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;        }
[解决办法]
循环x,y从0开始不行吗?
[解决办法]
初步估计是这样子的,另外HARD_KEY的数据类型是啥
C# code
    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;    } 

读书人网 >asp.net

热点推荐