Tried to modulize the functions a bit more and added decryption function.