function ceaser_cipher(){ this.alphabets=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']; } ceaser_cipher.prototype.encrypt=function(s,n){ var plain_text=[...s]; for(var i = 0, length1 = plain_text.length; i < length1; i++){ plain_text[i]=this.alphabets[this.alphabets.indexOf(plain_text[i])+n]; } return plain_text.toString(); }; ceaser_cipher.prototype.decrypt=function(s,n){ var cipher_text = [...s]; for(var i = 0, length1 = cipher_text.length; i < length1; i++){ cipher_text[i]=this.alphabets[this.alphabets.indexOf(cipher_text[i])-n]; } return cipher_text.toString(); }; var secret_msg = new ceaser_cipher(); var cipher_text = secret_msg.encrypt("abc",3); var plain_text = secret_msg.decrypt("def",3); console.log('The encoded one : ' + cipher_text); console.log('The decoded one : ' + plain_text);