5 kyu

Caesar Cipher Helper

1,441 of 5,147eugene-bulkin

Description:

Write a class that, when given a string, will return an uppercase string with each letter shifted forward in the alphabet by however many spots the cipher was initialized to.

For example:

var c = new CaesarCipher(5); // creates a CipherHelper with a shift of five
c.encode('Codewars'); // returns 'HTIJBFWX'
c.decode('BFKKQJX'); // returns 'WAFFLES'
c = new CaesarCipher(5) # creates a CipherHelper with a shift of five
c.encode('Codewars') # returns 'HTIJBFWX'
c.decode('BFKKQJX') # returns 'WAFFLES'
c = CaesarCipher(5); # creates a CipherHelper with a shift of five
c.encode('Codewars') # returns 'HTIJBFWX'
c.decode('BFKKQJX') # returns 'WAFFLES'
c = CaesarCipher.new(5); # creates a CipherHelper with a shift of five
c.encode('Codewars') # returns 'HTIJBFWX'
c.decode('BFKKQJX') # returns 'WAFFLES'
$c = new CaesarCipher(5);
$c->encode('Codewars'); // returns 'HTIJBFWX'
$c->decode('BFKKQJX'); // returns 'WAFFLES'
let c = CaesarCipher::new(5);
c.encode("Codewars"); // returns "HTIJBFWX"
c.decode("BFKKQJX"); // returns "WAFFLES"

If something in the string is not in the alphabet (e.g. punctuation, spaces), simply leave it as is.
The shift will always be in range of [1, 26].

Ciphers
Object-oriented Programming
Strings
Algorithms

Stats:

CreatedOct 27, 2013
PublishedOct 27, 2013
Warriors Trained12212
Total Skips2710
Total Code Submissions45044
Total Times Completed5147
JavaScript Completions1441
CoffeeScript Completions73
Python Completions2463
Ruby Completions432
PHP Completions755
Rust Completions70
Total Stars281
% of votes with a positive feedback rating92% of 661
Total "Very Satisfied" Votes561
Total "Somewhat Satisfied" Votes90
Total "Not Satisfied" Votes10
Total Rank Assessments10
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • eugene-bulkin Avatar
  • jhoffner Avatar
  • GiacomoSorbi Avatar
  • adam-tokarski Avatar
  • donaldsebleung Avatar
  • Voile Avatar
  • FArekkusu Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • XoRMiAS Avatar
  • saudiGuy Avatar
  • estem8 Avatar
Ad