# Caesar Cipher Encryptor

![](https://3743232000-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHW2IQuh2PFpWJDvBz2FF%2Fuploads%2Fgit-blob-1148f6b97b2d205f4b7f1143c4bfb94624c0578f%2FScreenshot%202023-01-20%20at%2020.51.56.png?alt=media)

* n, n

```jsx
const alphabet = `abcdefghijklmnopqrstuvwxyz`;
const aCode = alphabet.charCodeAt(0);
function caesarCipherEncryptor(str, key) {
  const answer = [];
  for (let i = 0; i < str.length; i++) {
    let code = str.charCodeAt(i) - aCode;
    code += key;
    code %= 26;
    answer.push(alphabet[code]);
  }

  return answer.join('');
}

// Do not edit the line below.
exports.caesarCipherEncryptor = caesarCipherEncryptor;
```
