refactored encrypt and decrypt to not reallocate memory