Skip to content

Instantly share code, notes, and snippets.

@jeffgca
Created May 20, 2011 18:09
Show Gist options
  • Select an option

  • Save jeffgca/983444 to your computer and use it in GitHub Desktop.

Select an option

Save jeffgca/983444 to your computer and use it in GitHub Desktop.
cheesy string xor'ing
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);
@jeffgca

jeffgca commented May 20, 2011

Copy link
Copy Markdown
Author

Why? Because xor'ing is now part of the websocket client -> server bit masking, although the implementation is slightly more complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment