Encryption and Decryption completed

Both functions now work as intended.
The error was in a wrong order of function calls
Code readability