Implementation skills of php custom hash function

墨辰丷
Release: 2023-03-31 13:22:01
Original
1353 people have browsed it

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;
}
Copy after login

Calling method:

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

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!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!