2345技术员联盟

PHP自定义Hash函数的实例解析

  • 来源:电脑技术网 原创
  • 时间:2015-05-14
  • 阅读:
  • 本文标签:PHPhash

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

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;
}

调用方法:

$TestString = 'www.dnjs.net';
print SimpleHash($TestString); 
// returns: 1082
本文来自电脑技术网www.it892.com),转载本文请注明来源.
本文链接:http://www.it892.com/content/web/php/0514603H015.html
推荐阅读
热点排行
无觅相关文章插件,快速提升流量