Skip to content

Instantly share code, notes, and snippets.

@GuillermoBlasco
Created April 3, 2015 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuillermoBlasco/5227ccb65fc399260a0a to your computer and use it in GitHub Desktop.
Save GuillermoBlasco/5227ccb65fc399260a0a to your computer and use it in GitHub Desktop.
tbb.xorcrypt
(function(window) {
'use strict';
var asByte = function(byte) {
var bytes = [];
for (var i = 0; i < this.length; ++i) {
bytes.push(this.charCodeAt(i));
}
return bytes;
};
function asString(array) {
var result = "";
for (var i = 0; i < array.length; i++) {
result += String.fromCharCode(array[i]);
}
return result;
}
var xor = function(array1, array2) {
var length = (array1.length > array2.length) ? array1.length : array2.length;
var array = []
for (var i = 0; i < length; i++) {
var value1 = (i < array1.length) ? array1[i] : 0;
var value2 = (i < array2.length) ? array2[i] : 0;
var value = value1 ^ value2;
array.push(value);
}
return array;
}
var xorcrypt = function(target, key) {
return asString(xor(asByte(target), asByte(key)));
}
var xordecrypt = function(target, key) {
return xorcrypt(target, key);
}
if (window.tbb == undefined) {
window.tbb = {};
}
window.tbb.xorcrypt = {
crypt : xorcrypt,
decrypt : xordecrypt
}
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment