首页 > 编程 > Php > 正文

php自定义hash函数实例

2021-11-29 18:31:33
字体:
来源:转载
供稿:网友

本文实例讲述了php自定义hash函数实现方法,分享给大家供大家参考,具体分析如下:

这里演示php实现的一个简单hash算法,可以用来加密,不过这个函数过于简单,不能用来解密。

  1. function SimpleHash($str){   
  2.   $n = 0; 
  3.   // The magic happens here: 
  4.   // I just loop trough all letters and add the 
  5.   // ASCII value to a integer variable.  
  6.   for ($c=0; $c < strlen($str); $c++) 
  7.     $n += ord($str[$c]); 
  8.   // After we went trough all letters 
  9.   // we have a number that represents the 
  10.   // content of the string 
  11.   return $n

调用方法:

  1. $TestString = 'www.Cuoxin.com'
  2. print SimpleHash($TestString);  
  3. // returns: 1082

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表