日期:2014-05-18  浏览次数:20834 次

请问有没有人能够用C# 写一个函数跟这个javascript函数功能一样呢
function(l) {
  var j = "";
  var s, q, o = "";
  var r, p, n, m = "";
  var k = 0;
  do {
  s = l.charCodeAt(k++);
  q = l.charCodeAt(k++);
  o = l.charCodeAt(k++);
  r = s >> 2;
  p = ((s & 3) << 4) | (q >> 4);
  n = ((q & 15) << 2) | (o >> 6);
  m = o & 63;
  if (isNaN(q)) {
  n = m = 64
  } else {
  if (isNaN(o)) {
  m = 64
  }
  }
  j = j + keys.charAt(r) + keys.charAt(p);
  s = q = o = "";
  r = p = n = m = ""
  } while ( k < l . length );
  return j



我的基础不太扎实,charat 跟 charcodeat 还有右移这些不熟。谢谢了! 调试我可以。

------解决方案--------------------
不会是 base64吧?

回家吃饭
------解决方案--------------------
C# code

        public string function(string l)
        {
            string keys = "ADFEWQTGSDFAEREWRW";
            string j = string.Empty;
            char s, q, o;
            char r, p, n, m;
            int k = 0;
            while (k < l.Length)
            {
                s = l[k++];
                q = l[k++];
                o = l[k++];
                r = (char)(s >> 2);
                p = (char)(((s & 3) << 4) | (q >> 4));
                n = (char)((((q & 15) << 2) | (o >> 6)));
                m = (char)(o & 63);

                if (char.IsNumber(q))
                {
                    n = m = (char)64;
                }
                else
                {
                    if (char.IsNumber(o))
                    {
                        m = (char)64;
                    }
                }
                j = j + keys[r] + keys[p];
                s = q = o = char.MinValue;
                r = p = n = m = char.MinValue;
            }
            return j;
        }