1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function xorConvert (text, key) {
var kL = key.length;

return Array.prototype
.slice.call(text)
.map(function (c, index) {
return String.fromCharCode(c.charCodeAt(0) ^ key[index % kL].charCodeAt(0));
}).join('');
}

var key = "RandomPassKey";
var txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@£#$%^&*()[]{};:'\",.<>/\\";
var cipherText = xorConvert(txt, key);

assert(xorConvert(cipherText, key) === txt);