Created
April 3, 2015 21:01
-
-
Save GuillermoBlasco/5227ccb65fc399260a0a to your computer and use it in GitHub Desktop.
tbb.xorcrypt
This file contains 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
(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