Optimized XOR Cipher Encryption in ActionScript 3

by troy on October 11, 2009

Been wanting to try implementing a XOR cipher for awhile,   a very simple cheap to implment encryption, that actually has a rich history dates back  to paper and teletype and world war II (as a one-time pad).

It can be used for anything that can be encoded into a string, be it across the wire, in a shared object, configuration files.  It's not high security but it's better than being naked.

In looking around I found on larger strings or XML there were ways to improve the speed.  Also I wanted something easy to send across the wire (so pres escaped).  It also includes a random string generator for the key.

The AS3 source can be found here on google code XORCipher.as

A sample unit test case is here. It's simple to use:

1
2
3
4
 
var xord:String = xor.xor_escape("Hello World"); //String to Xor
 
var xord2:String = xor.xor_unescape(xord); //Xored to plain text String e.g. Hello World

REFERENCES

[1] Danny Patternson's version (less optimized needs flex)

[2] Wikipedia XOR Cipher

Leave a Comment

Previous post:

Next post: