Skip to content

Instantly share code, notes, and snippets.

@geforester
Created November 6, 2018 08:53
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 geforester/74f95c943b6dfe04e7782c2db2e429ea to your computer and use it in GitHub Desktop.
Save geforester/74f95c943b6dfe04e7782c2db2e429ea to your computer and use it in GitHub Desktop.
(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 = ''
if (!key) {
key = 6
}
for (var i = 0; i < str.length; ++i) {
output += String.fromCharCode(key ^ str.charCodeAt(i))
}
return output
}
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment