首页 新闻 会员 周边

AS转C#代码问题

0
悬赏园豆:20 [已解决问题] 解决于 2014-10-29 17:20

好久没碰flash了.. 请问熟悉AS的博友如此转换是否正确?

AS

        public static function decodeBytes(param1:ByteArray) : ByteArray
        {
            var a:uint;
            var b:uint;
            var c:uint;
            var d:uint;
            param1.position = 0;
            var result:* = new ByteArray();
            param1.readBytes(result);
            var c:* = result.length;
            var d:uint;
            while (true)
            {
                // label
                a = 0;
                while (a++ < c)
                {
                    // label
                    result[d] = result[d] ^ b;
                    if (++d >= c)
                    {
                        break;
                    }// end if
                }// end while
                d = ++d + d;
                if (d >= c)
                {
                    break;
                }// end if
            }// end while

            return result;
      }// end function

c#

     byte[] DecodeBytes(byte[] orginalBytes)
        {
            int a = 0;
            int b = 0;
            int c = 0;
            int d = 0;

            c = orginalBytes.Length;
            var result = new byte[c];

            while (true)
            {
                a = 0;
                while (a++ < c)
                {
                    result[d] = byte.Parse((orginalBytes[d] ^ b).ToString(CultureInfo.InvariantCulture));
                    if (++d >= c)
                    {
                        break;
                    }
                }
                d = ++d + d;

                if (d >= c)
                {
                    break;
                }
            }

            return result;
        }
秦逸辰的主页 秦逸辰 | 初学一级 | 园豆:136
提问于:2014-10-29 09:05
< >
分享
最佳答案
1

正确,不过,代码很多要优化,其中:

result[d] = byte.Parse((orginalBytes[d] ^ b).ToString(CultureInfo.InvariantCulture));

有点脱裤子放屁的嫌疑,下面的呢?

result[d] = (byte)(originalBytes[d]^b)

收获园豆:10
519740105 | 大侠五级 |园豆:5810 | 2014-10-29 10:04

谢谢, 光想着转换的逻辑对不对,没考虑优化.谢谢指点.

秦逸辰 | 园豆:136 (初学一级) | 2014-10-29 17:19
其他回答(1)
0

正确。

收获园豆:10
CaiYongji | 园豆:1267 (小虾三级) | 2014-10-29 09:35

谢谢.

支持(0) 反对(0) 秦逸辰 | 园豆:136 (初学一级) | 2014-10-29 17:20
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册