Note: This is a classic learning implementation. For real cryptography, use modern authenticated encryption.