(str, key)
| 10 | * @return {string} encrypted string |
| 11 | */ |
| 12 | const XORCipher = (str, key) => { |
| 13 | if (typeof str !== 'string' || !Number.isInteger(key)) { |
| 14 | throw new TypeError('Arguments type are invalid') |
| 15 | } |
| 16 | |
| 17 | return str.replace(/./g, (char) => |
| 18 | String.fromCharCode(char.charCodeAt() ^ key) |
| 19 | ) |
| 20 | } |
| 21 | |
| 22 | export default XORCipher |