If this is a learning exercise, great - do what everyone else said.
If this is going anywhere near production systems, confidential data, etc - stop right there. DO NOT WRITE YOUR OWN ENCRYPTION CODE, EVER. There are a million very subtle ways to screw it up and only one way to get it right. I'm sure you're a regular genius and all, but the strong likelihood is that you will unintentionally write subtly broken, easily compromised code without even knowing it; everyone does - that's just how it works.
If this is for a real project, do yourself a massive favour and use some tried and tested encryption libraries which have suffered the slings and arrows of outrageous fortune, survived the trials of life in the wild world, been attacked, patched and are still standing.
Besides, I'm sure you've got enough to do already :)