Last active
September 24, 2020 09:23
-
-
Save iamspark1e/75c73cd8545affc93233b06a0e90bff7 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
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