当前位置: 代码迷 >> ASP.NET >> vb代码转ASP.NET C#代码~ 急求
  详细解决方案

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

热度:3512   发布时间:2013-02-25 00:00:00.0
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;    }
  相关解决方案