This article mainly introduces the php custom hash function. The example analyzes the implementation skills of the hash function and implements simple encryption functions, which has some reference value, for more information about how to implement php custom hash functions, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
A simple hash algorithm implemented by php can be used for encryption. However, this function is too simple to be used for decryption.
Function SimpleHash ($ str) {$ n = 0; // The magic happens here: // I just loop trough all letters and add the // ASCII value to a integer variable. for ($ c = 0; $ c <strlen ($ str); $ c ++) $ n + = ord ($ str [$ c]); // After we went trough all letters // we have a number that represents the // content of the string return $ n ;}
Call method:
$ TestString = 'www .bitsCN.com '; print SimpleHash ($ TestString); // returns: 1082
I hope this article will help you with php programming.