Home  >  Article  >  Backend Development  >  Implementation skills of php custom hash function

Implementation skills of php custom hash function

墨辰丷
墨辰丷Original
2018-06-11 10:42:301343browse

This article mainly introduces the PHP custom hash function, and analyzes the implementation skills of the hash function with examples. It can realize simple encryption functions and has certain reference value. Friends in need can refer to this article

The example describes the implementation method of PHP custom hash function. The specific analysis is as follows:

Here demonstrates 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

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:

$TestString = &#39;www.jb51.net&#39;;
print SimpleHash($TestString); 
// returns: 1082

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

How to automatically generate forms in PHP

php predefined variables on the server side$ _SERVER method

php method of operating MySQL database

The above is the detailed content of Implementation skills of php custom hash function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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