No offense, but Rogem's first algo is not a good one to rely on. Encoding something (encrypting or hashing) should not have its security depend upon the method. That is, once one knows that Rogem uses the method just described, it's not hard to reverse engineer it - i.e. a proper collision table.
Encryption is a means of taking a piece of information and writing it in a way which is difficult, but rarely impossible, to reverse back to the original piece of information.
Hashing is a means of taking a piece of information and tweaking it in a fashion that it's virtually impossible to get back the original piece of information. Examples of hashing are MD5 and SHA (1, 256, 512, ...).
Except for one method, all encoding used today relies upon the fact that it's very, very, very hard to break -- but
not impossible. If it takes 40 years to decrypt information which is only useful for 4 days, then who will care when it's cracked? If the information is so important that it ought not to be cracked for 100 years then it will matter very much that it's cracked in 40 years.
OK. The pedantic stuff over, let's get to the practical.
1) When hashing: Use a wacky seed like frost demonstrates. Make that seed unique to each program and heavily protect the server that holds the seed. Unless you reset everyone's information that's protected by that seed, you can never change it. Hashing will only work for so long. MD5 was shown to be able to find 2 "phrases" to come to the same code awhile back. Doesn't mean a whole lot from a practical point of view, but you should be using sha1 on PHP 4 servers and the best supported hash for PHP 5 servers (see
http://www.php.net/hash for details).
2) Public Key Cryptography is what's currently used to protect most data around. It's based off of the principle that it will take computers a long time to find the 2 prime number factors of a single composite number. Not that it's impossible, just very time consuming. This is what's behind RSA. If you're reading this and wondering, "Is he saying that if I find a way to factor numbers efficiently I will have cracked most of the cryptography in current use?" The answer is yes! Amazing, but true. That's how hard factoring really large numbers can be.
There's a lot of math behind it, but a bit of research on the RSA algo will give you a good start to figuring out how you wish to implement such a methodology.
3) In all of my research there is only one algorithm which when used correctly can guarantee 100% security: The One-Time Pad. It's been around for a while; is fairly easy conceptually; very programmatically heavy; doesn't "support" public-key cryptography; and is still in use today for the most secretive documents of any govt. Remember though: break its rules once and you jeopardize everything you've encrypted. This isn't just some hair-brained idea either: it has been proven (and I can prove it too as the mathematical proof is fairly straight forward) that this method is uncrackable. Try character frequency analysis; word analysis; ... I don't care what you try ... throw as many Crays as you want at it and the text will stay encrypted. It's not used today in day-to-day encryption because there's no known way of deploying it using public-key cryptography. I just love this method so I had to mention it.
When picking a method, use this guide:
Hashing
Use when you don't want the original information discoverable for a period of years. MD5 should not be used as it has been shown to have sufficiently frequent collisions given today's computing power. SHA1 should be used if other more complex algos are not available.
Public-Key Cryptography
Use when you want to be able to find the original information, but want it to be hidden from others for a period of years.
One-Time Pad Encryption
Use for the most sensitive of data that must be recoverable. Time frame is irrelevant given correct implementation. Not appropriate for situations where you cannot safely transmit the decryption key pad to others (e.g. the web).