Modularized encrypt and decrypt functions