Fixed up algorithm.  Encryption seems to work. Decryption does not.