Simple hand-made hash function
This example shows how to create a one-way encryption method by using a very simplified algorithm.
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; }
Author:
Jonas John
License:
Public Domain
Language:
PHP
Created:
03/05/2007
Updated:
10/29/2007
Tags:
encode, encryption, hash, string
$TestString = 'www.jonasjohn.de'; print SimpleHash($TestString); // returns: 1620
Sorry folks, comments have been deactivated for now due to the large amount of spam.
Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!
Older comments:
the highest possible value is 255
ceil(hash/255);
please excuse my bad English.. ;)
$x = "fGuxnWJ5abcdef";
and in vb and java hshcode method i get this result after hashing in hex mode "74 C4 AB FB"
Now i want to get same hash result in php which i get from java and VB.
But i want 4 bytes in ascii.
Given result is in hex mode. Please help me out