Created
November 6, 2018 08:53
-
-
Save geforester/74f95c943b6dfe04e7782c2db2e429ea 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 = '' | |
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