As
mortis recommended, Applied Cryptography is a great book for learning how to write and understand cryptographic algorithms. If, however, you are looking for a simpler approach to just getting your feet wet with cryptography, I strongly recommend
Simon Singh's "The Code Book". It's a great introduction to cryptographic ideas, all the way from a simple substitution cipher, through Enigma, and onto today's public key cryptosystems.