好久没碰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; }
正确,不过,代码很多要优化,其中:
result[d] = byte.Parse((orginalBytes[d] ^ b).ToString(CultureInfo.InvariantCulture));
有点脱裤子放屁的嫌疑,下面的呢?
result[d] = (byte)(originalBytes[d]^b)
谢谢, 光想着转换的逻辑对不对,没考虑优化.谢谢指点.
正确。
谢谢.