ga-wdi-boston / cipher-challenge

Other
0 stars 70 forks source link

General Assembly Logo

Caesar Cipher Challenge

Prerequisites

Instructions

  1. Fork and clone this repository.
  2. Change into the new directory.
  3. Install dependencies.
  4. Create and checkout a new branch to work on.
  5. Fulfill the listed requirements.

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.

Ceasar Cipher

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.

Caesar cipher - Wikipedia, the free encyclopedia

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.

Requirements

  1. Plan using the whiteboard for about 10 minutes.

  2. Implement your ROT13Cipher module.

  3. 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'
  4. 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.

Bonus

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.

Additional Resources

License

  1. All content is licensed under a CC­BY­NC­SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.