Cleaned up code. Separated common code into file that will be shared by
both encryption and decryption algorithms.