Building the complete encrypt, decrypt next function.