Created
May 20, 2011 18:09
-
-
Save jeffgca/983444 to your computer and use it in GitHub Desktop.
cheesy string xor'ing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sys = require('sys'); | |
| var L = function(str) {console.log(str)} | |
| function xor_str(subject, key) { | |
| var the_res = ""; | |
| for (i = 0; i < subject.length; i++) { | |
| var cur = key.charCodeAt((i % key.length)); | |
| var c = String.fromCharCode(cur ^ subject.charCodeAt(i)); | |
| the_res += c; | |
| } | |
| return the_res; | |
| } | |
| var plain = "This is some plain text..."; | |
| L("Plain text: " + plain); | |
| var key = "ACBDBEB"; | |
| var xord = xor_str(plain, key); | |
| L("Crypt text: " + xord); | |
| var decrypt= xor_str(xord, key); | |
| L("De-crypted: " + decrypt); | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why? Because xor'ing is now part of the websocket client -> server bit masking, although the implementation is slightly more complex.