Шифр Цезаря

Шифр Цезаря

var Cesar = new 
(function Cesar(offset){
    var ACode = "a".charCodeAt(0), alphabetSize = 26, Self = this;
    this.encodeChar = function(ch){return (ch+offset-ACode+alphabetSize)%alphabetSize + ACode; };
    this.decodeChar = function(ch){return (ch-offset-ACode+alphabetSize)%alphabetSize + ACode; };
    this.encode =
        function(str){ var res="", chr;
            for(var a=0;a<str.length;++a) 
                if((chr=str.charCodeAt(a)) && (chr>=ACode) && (chr-ACode<alphabetSize))
                    res+=String.fromCharCode(Self.encodeChar(chr));
                else res+=str.charAt(a);
            return res;
        };
    this.decode =
        function(str){ var res="";
            for(var a=0;a<str.length;++a) 
                if((chr=str.charCodeAt(a)) && (chr>=ACode) && (chr-ACode<alphabetSize))
                    res+=String.fromCharCode(Self.decodeChar(chr));
                else res+=str.charAt(a);
            return res;
        };
})(3);
alert(Cesar.encode("f@ck yeah"));
alert(Cesar.decode(Cesar.encode("f@ck yeah")));