main.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
//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