-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathrot13.js
42 lines (38 loc) · 1.23 KB
/
rot13.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Given an input string, returns a ROT13 copy of the string.
*
* A substitution cipher is a method of encrypting an input string
* by replacing each letter of the input with some other letter.
*
* ROT13 is a substitution cipher where each letter is replaced by
* the letter that is 13 letters after it in the alphabet, wrapping
* back to the start of the alphabet if necessary.
*
* For example, every instance of 'A' is replaced with 'N', 'M' with 'Z',
* 'R' with 'E', and so on.
*
* See https://en.wikipedia.org/wiki/ROT13
*
* Play with: https://rot13.com/
*
* Because there are 26 letters in the alphabet, we can "decrypt" a
* rot13-encrypted string by applying rot13 again.
*
* (No, this isn't particularly secure.)
*
* @example
* rot13('Hello, world!'); // => 'Uryyb, jbeyq!'
* rot13('Uryyb, jbeyq!'); // => 'Hello, world!'
*
* @param {string} string - The string to replace a character in
* @returns {string} A lowercase copy of the input string
*/
function rot13(string) {
// This is your job. :)
}
if (require.main === module) {
console.log('Running sanity checks for rot13:');
// Add your own sanity checks here.
// How else will you be sure your code does what you think it does?
}
module.exports = rot13;