|
| 1 | +# Caesar's Cipher |
| 2 | +[Edabit Problem](https://edabit.com/challenge/a33jdGXkaQRtK9ZTs) |
| 3 | + |
| 4 | +Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar's cipher (check ***Resources*** tab for more info) shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the case of a rotation by *3, w, x, y* and *z* would map to *z, a, b* and *c*. |
| 5 | + |
| 6 | +Create a function that takes a string *s* (text to be encrypted) and an integer *k* (the rotation factor). It should return an encrypted string. |
| 7 | + |
| 8 | +## Example: |
| 9 | +```javascript |
| 10 | +caesarCipher("middle-Outz", 2) ➞ "okffng-Qwvb" |
| 11 | + |
| 12 | +// m -> o |
| 13 | +// i -> k |
| 14 | +// d -> f |
| 15 | +// d -> f |
| 16 | +// l -> n |
| 17 | +// e -> g |
| 18 | +// - - |
| 19 | +// O -> Q |
| 20 | +// u -> w |
| 21 | +// t -> v |
| 22 | +// z -> b |
| 23 | + |
| 24 | +caesarCipher("Always-Look-on-the-Bright-Side-of-Life", 5) |
| 25 | +➞ "Fqbfdx-Qttp-ts-ymj-Gwnlmy-Xnij-tk-Qnkj" |
| 26 | + |
| 27 | +caesarCipher("A friend in need is a friend indeed", 20) |
| 28 | +➞ "U zlcyhx ch hyyx cm u zlcyhx chxyyx" |
| 29 | +``` |
| 30 | + |
| 31 | +### Notes: All test input will be a valid ASCII string. |
| 32 | + |
| 33 | +## By: arindal1 |
| 34 | +***[GitHub](https://github.com/arindal1)*** |
0 commit comments