Created
November 6, 2018 09:12
-
-
Save geforester/79a06f71c9576d868ab9090ab0edd537 to your computer and use it in GitHub Desktop.
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 (root, factory) { | |
'use strict' | |
/* global define */ | |
if (typeof define === 'function' && define.amd) { | |
define([], factory) | |
} else if (typeof exports === 'object') { | |
module.exports = factory() | |
} else { | |
root.xorCrypt = factory() | |
} | |
}(this, function () { | |
'use strict' | |
/** | |
* Encrypt or decrypt a string with the given XOR key. | |
* | |
* @name xorCrypt | |
* @param {string} str - The string to encrypt. | |
* @param {int} [key=6] - The XOR key to use when encrypting. | |
* | |
* @return The resulting XOR'ed string. | |
*/ | |
return function xorCrypt (str, key) { | |
var output = '',result = '', hex | |
if (!key) { | |
key = 5 | |
} | |
for (var i = 0; i < str.length; ++i) { | |
output += String.fromCharCode( key ^ str.charCodeAt(i)) | |
} | |
for (i=0; i<output.length; i++) { | |
hex = output.charCodeAt(i).toString(16); | |
result += ("000"+hex).slice(-4); | |
} | |
return result; | |
} | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment