php 自定义一个简单hash函数示例
内容摘要
这篇文章主要为大家详细介绍了php 自定义一个简单hash函数示例,具有一定的参考价值,可以用来参考一下。
php实现的一个简单hash算法,可以用来加密,不过这个函数过于简单,不能用
php实现的一个简单hash算法,可以用来加密,不过这个函数过于简单,不能用
文章正文
这篇文章主要为大家详细介绍了php 自定义一个简单hash函数示例,具有一定的参考价值,可以用来参考一下。
php实现的一个简单hash算法,可以用来加密,不过这个函数过于简单,不能用来解密,php自定义一个简单的hash函数,对此感兴趣的朋友,看看idc笔记做的技术笔记。经测试代码如下:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <code class = "php" > /** * 简单hash算法 * * @param * @arrange (www.idcnote.com) **/ 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.idcnote.com' ; print SimpleHash( $TestString ); // returns: 1620 /*** 来自php教程(www.idcnote.com) ***/ </code> |
注:关于php 自定义一个简单hash函数示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释