Work in lib/challenge.js
. A pull request is not required,
but it is necessary if you want a code review.
You may wish to refer to FAQs related to forking, cloning.
In cryptography, a Caesar cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. The method is named after Julius Caesar, who used it in his private correspondence.
We're going to implement a simple Caesar Cipher called ROT13 ("rotate by 13 places"). The transformation can be represented by aligning two alphabets:
Plain: abcdefghijklmnopqrstuvwxyz
Cipher: nopqrstuvwxyzabcdefghijklm
ROT13 is its own inverse; that is, to undo ROT13, the same algorithm is applied, so the same action can be used for encoding and decoding. The algorithm provides virtually no cryptographic security, and is often cited as a canonical example of weak encryption. ROT13 is used in online forums as a means of hiding spoilers, punchlines, puzzle solutions, and offensive materials from the casual glance.
Plan using the whiteboard for about 10 minutes.
Implement your ROT13Cipher
module.
You should implment a method .encode
that takes a single word as an
argument and returns the encrypted text. Read and run the tests. Try your
code out in node
. You should be able to use your code like this:
let cipher = require('./lib/challenge');
cipher.encode('hello'); //=> 'uryyb'
cipher.encode('jeff'); //=> 'wrss'
Implement a .decode
method that takes an encrypted word as an argument and
returns the unencrypted text.
NOTE: It is okay to hard-code alphabet
and rotated
. Try generating them
with code after you get the solution working.
First, change your cipher so that it can take a string with spaces, allowing you to encode and decode entire sentences, not just words.
cipher.encode('hello jeff'); //=> 'uryyb wrss'
Then, change your cipher again so that it can also take a string with upper-case characters.
cipher.encode('Hello Jeff'); //=> 'Uryyb Wrss'
Next, implement a ROT25 cipher. You should implement both .ecnode
and
.decode
methods. Test drive your solution, and use the module pattern.
let cipher = require('./lib/challenge').rot25;
cipher.encode('Hello Jeff'); //=> 'Gdkkn Idee'
Very Challenging: Finally, implement a cipher that takes a number between
one and twenty-five as a parameter when it is instantiated. This number n
will be used to rotate the alphabet by n
places. For example, if you
instantiate your cipher with 13, you should get the same results as the
in-class lab. Use ROT-n Rotation Encryption online to
build your test strings for each potential input.