repl.it
@paulshorey/PaulsCaesarCipher
JavaScript

Wanted to see if I could quickly do this in Javascript without peeking at online solutions or hints.

//CaesarCipher
var caesar = function(input) {
  
  var key_original = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz [email protected]#$%^&*()_+-=[]\\{}|;\':",./<>?`~';
  var key_ciphered = '?`~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz [email protected]#$%^&*()_+-=[]\\{}|;\':",./<>';
  
  return {
    encrypt: function(input){
      var output = '';
      var inputArray = input.split('');
      input.split('').forEach(function(char){
        output += key_ciphered[ key_original.indexOf(char) ];
      });
      return output;
    },
    decrypt: function(input){
      var output = '';
      var inputArray = input.split('');
      input.split('').forEach(function(char){
        output += key_original[ key_ciphered.indexOf(char) ];
      });
      return output;
    }
  }
  
}();
// run it
var encrypted = caesar.encrypt("Hello secret friends! This is my secret message. ;) ...");
console.log(encrypted);
console.log(caesar.decrypt(encrypted));
Native Browser JavaScript