function XOREncryption(s: string, key: string) {
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 = "TypeScript programming language is a strict syntactical superset of JavaScript";
const key = "secretkey";
const cipher = XOREncryption(s, key);
console.log(cipher);
const noncipher = XOREncryption(cipher, key);
console.log(noncipher);
/*
run:
"'6 E
E
EESE
EEE>
"
"TypeScript programming language is a strict syntactical superset of JavaScript"
*/