Encryption functional but decryption contains a few bugs