Encode strings by subtracting one from each character code
Try looping through it with a simple for loop:

var b = '';
for (var i = 0; i &lt; a.length; i++)
{
   b += String.fromCharCode(a.charCodeAt(i) - 1)
}
return b;