function EncryptMessage(message) {
var encryptedArr = [];
for(i=0;i<message.length+1;i++){
var unicode = message.charCodeAt(i);
var encryptedUnicode;
var newCharacter = String.fromCharCode(encryptedUnicode);
if(unicode>=65 && unicode <=77 )
encryptedUnicode = unicode + 13;
else if (unicode>=78 && unicode <=90 && unicode!==" ")
encryptedUnicode = unicode - 13;
else if (unicode === 32)
encryptedUnicode = unicode;
encryptedArr.push(newCharacter);
}
return encryptedArr.toString();
}
EncryptMessage("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.")
should decode to "THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX." Unfortunately, the output is not as expected. Instead of giving the decoded message, it returns "T,H,E, ,Q,U,I,C,K, ,B,R,O,W,N, ,D,O,G, ,J,U,M,P,E,D, ,O,V,E,R, ,T,H,E, ,L,A,Z,Y, ,F,O,X,X"