php自定义hash函数实例

yipeiwu_com5年前PHP代码库

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

这里演示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.jb51.net';
print SimpleHash($TestString); 
// returns: 1082

希望本文所述对大家的php程序设计有所帮助。

相关文章

如何打开php的gd2库

如何打开php的gd2库

第一步:找到 php.ini 通常,该文件在php安装目录下,如果忘记路径可以在你使用的web服务软件上查询。 第二步:用记事本打开该文件,并按 “ctrl+F” 输入 “extens...

The specified CGI application misbehaved by not returning a complete set of HTTP headers

是错误报告: The specified CGI application misbehaved by not returning a complete set of HTTP heade...

PHP版自动生成文章摘要

自动生成文章摘要[JavaScript 版本]。 我们在写BLOG这样的程序时经常需要显示文章前一部分的,但是又怕不恰当的截断破坏封闭标签以造成整 个文档结构破坏,使用我的函数...

php 编写安全的代码时容易犯的错误小结

1.不转意html entities 一个基本的常识:所有不可信任的输入(特别是用户从form中提交的数据) ,输出之前都要转意。 echo $_GET['usename'] ; 这个例...

学习php设计模式 php实现桥梁模式(bridge)

学习php设计模式 php实现桥梁模式(bridge)

一、桥梁模式结构图   二、桥梁模式中主要角色 抽象化(Abstraction)角色:定义抽象类的接口并保存一个对实现化对象的引用。 修正抽象化(Refined Abstra...