As you have seen, it takes around ten lines of code just to encrypt data, however the end result is that you get encrypted text that is exceptionally hard to decrypt without knowledge of the key and IV. Once you have mastered encryption, decryption is fairly easy as it shares most of the same concepts. Here is the same script again, this time it encrypts then decrypts the information:
Note that we actually call mcrypt_generic_deinit() then mcrypt_generic_init() immediately afterwards - this is important for the encryption to work properly, and you must not forget to do this.
Author's Note: it is crucial that you do not forget to deinit() after you encrypt, then call init() again when you want to decrypt - if you do not believe me, try commenting these lines out and see what happens!
The output of that script is too crazy to print here because encrypted data uses a much wider range of characters than just A-Z - try the script for yourself and see what your ciphertext looks like.