Skip to content

Instantly share code, notes, and snippets.

@iamspark1e
Last active September 24, 2020 09:23
Show Gist options
  • Save iamspark1e/75c73cd8545affc93233b06a0e90bff7 to your computer and use it in GitHub Desktop.
Save iamspark1e/75c73cd8545affc93233b06a0e90bff7 to your computer and use it in GitHub Desktop.
const customKey = require("../vars").customKey
const XORCipher = {
encode: function (data) {
data = xorStrings(customKey, data);
return btoa(data);
},
decode: function (data) {
data = atob(data);
return xorStrings(customKey, data);
}
};
function xorStrings(key, input) {
var output = ''
for(var i = 0; i < input.length; i++) {
var c = input.charCodeAt(i)
var k = key.charCodeAt(i % key.length)
output += String.fromCharCode(c ^ k);
}
return output
}
module.exports = XORCipher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment