MCPcopy Create free account
hub / github.com/TheAlgorithms/JavaScript / XORCipher

Function XORCipher

Ciphers/XORCipher.js:12–20  ·  view source on GitHub ↗
(str, key)

Source from the content-addressed store, hash-verified

10 * @return {string} encrypted string
11 */
12const 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
22export default XORCipher

Callers 1

XORCipher.test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected