Home > Backend Development > PHP Tutorial > PHP custom hash function example_PHP tutorial

PHP custom hash function example_PHP tutorial

WBOY
Release: 2016-07-13 09:54:42
Original
821 people have browsed it

php custom hash function example

This article describes the implementation method of php custom hash function. Share it with everyone for your reference. The specific analysis is as follows:

Here is a demonstration of a simple hash algorithm implemented in PHP, which can be used for encryption, but this function is too simple and cannot be used for decryption

 ?

1

2

3

4

5

6

7

8

9

10

11

12

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;

}

1

2

3

1

2

3

$TestString = 'www.jb51.net';

print SimpleHash($TestString);

// returns: 1082

4

5

6

8 9 10 11 12
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; }
Calling method:  ?
1 2 3 $TestString = 'www.jb51.net'; print SimpleHash($TestString); // returns: 1082
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/994739.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/994739.htmlTechArticlephp custom hash function example This article describes the implementation method of php custom hash function. Share it with everyone for your reference. The specific analysis is as follows: Here is a simple ha implemented in php...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template