I'm looking to make a program to encrypt a string using a vigenere cipher. So far, I have been successful in doing this, apart from special characters (e.g. spaces, full stops, commas, etc). 

I have come to this solution, which includes the correct special characters. However, everything after the first special character in the string becomes gibberish. They are not special characters, they are still in the alphabet, although they don't match with the cipher. I *cannot* work out why this happening. I've tried several totally different methods, and all of them lead to this same error. This is the neatest method I've come up with so far, but it still doesn't work (for this example you can assume that the text and the key are the same length).

```
for (i=0, l=[], k=[], output=""; i < text.length; i++) {
  l[i] = (text.charCodeAt(i)) - 97;
  k[i] = (key.charCodeAt(i)) - 97;
  if ((l[i] > -1) && (l[i] < 26)) { // if the ASCII code is between 0 and 25
    ans = parseInt(encryptLetter(l[i], k[i]));
    output += String.fromCharCode(97 + ans);
  };
  if ((l[i] < 0) || (l[i] > 25)) { // if the ASCII code is not between 0 and 25
    output += String.fromCharCode(97 + l[i])
  };
};

function encryptLetter(l, k) {
  en = l + k;
  if (en > 25) { // if encrypted letter is greater than 26.
    en -= 26;
  }
  return en;
}

```

If you need, you can test the encryption [here](http://rumkin.com/tools/cipher/vigenere.php). Any help would be greatly appreciated.

Edit:
I have noticed that every four special characters, there is a block of regular characters that is correct to the cipher. I have *no idea* why. It completely baffles me.