Hello,

I have a XOR class in both Flex and Royale projects.
This class share 100% the same code.

Executing this method in both Flex and Royale with "AAA" string I get the
same result but for example with the string "a", I get different results.
Seems to me that String.fromCharCode return a space string in special char
codes like 12 (I saw that the same happens in pure JS).

Flex:

var result1:String = XOR.encode("AAA", "MyKey"); // result = DDgK
var result2:String = XOR.encode("a", "MyKey");   // result = LA==

Royale:

var result1:String = XOR.encode("AAA", "MyKey"); // result = DDgK
var result2:String = XOR.encode("a", "MyKey"); // result = LAAA

public class XOR
{
private static function xor(source:String, key:String):String
{
var result:String = new String();
for (var i:Number = 0; i < source.length; i++)
{
if (i > (key.length - 1))
key += key;
result += String.fromCharCode(source.charCodeAt(i) ^ key.charCodeAt(i));
}
return Strings.toUTF8(result);
}

public static function encode(source:String, key:String):String
{
return Base64.encode(xor(source, key));
}
public static function decode(source:String, key:String):String
{
if (source == null)
return null;
return xor(Base64.decode(source), key);
}
}

Reply via email to