function XOREncryption(s, key) {
const slen = s.length, keylen = key.length;
let result = '';
for (let i = 0; i < slen; i++) {
result += String.fromCharCode(s.charCodeAt(i) ^ key.charCodeAt(i % key.length));
}
return result;
}
const s = "Node.js is an open-source cross-platform back-end JavaScript runtime environment";
const key = "secretkey";
const cipher = XOREncryption(s, key);
console.log(cipher);
const noncipher = XOREncryption(cipher, key);
console.log(noncipher);
/*
run:
=
KEE^E
H
E
^
E>
K
T
Node.js is an open-source cross-platform back-end JavaScript runtime environment
*/