{"id":101,"date":"2013-04-24T11:34:54","date_gmt":"2013-04-24T03:34:54","guid":{"rendered":"http:\/\/www.zyuns.com\/?p=101"},"modified":"2015-02-15T20:51:34","modified_gmt":"2015-02-15T12:51:34","slug":"php-de-ge-zhong-hash-suan-fa-shi-xian","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=101","title":{"rendered":"php\u7684\u5404\u79cdhash\u7b97\u6cd5\u5b9e\u73b0"},"content":{"rendered":"<pre class=\"wrap:true lang:default decode:true \">&lt;?php\nfunction DJBHash($str) \/\/ 0.22\n{\n$hash = 0;\n$n = strlen($str);\nfor ($i = 0; $i &lt;$n; $i++)\n{\n$hash += ($hash &lt;&lt;5 ) + ord($str[$i]);\n}\nreturn $hash % 701819;\n}\n\nfunction ELFHash($str) \/\/ 0.35\n{\n$hash = $x = 0;\n$n = strlen($str);\nfor ($i = 0; $i &lt;$n; $i++)\n{\n$hash = ($hash &lt;&lt;4) + ord($str[$i]);\nif(($x = $hash &amp; 0xf0000000) != 0)\n{\n$hash ^= ($x&gt;&gt; 24);\n$hash &amp;= ~$x;\n}\n}\nreturn $hash % 701819;\n}\n\nfunction JSHash($str) \/\/ 0.23\n{\n$hash = 0;\n$n = strlen($str);\nfor ($i = 0; $i &lt;$n; $i++)\n{\n$hash ^= (($hash &lt;&lt;5) + ord($str[$i]) + ($hash&gt;&gt; 2));\n}\nreturn $hash % 701819;\n}\n\nfunction SDBMHash($str) \/\/ 0.23\n{\n$hash = 0 ;\n$n = strlen($str);\nfor ($i = 0; $i &lt;$n; $i++)\n{\n$hash = ord($str[$i]) + ($hash &lt;&lt;6 ) + ($hash &lt;&lt;16 ) - $hash;\n}\nreturn $hash % 701819;\n}\n\nfunction APHash($str) \/\/ 0.30\n{\n$hash = 0 ;\n$n = strlen($str);\nfor ($i = 0; $i &lt;$n; $i++)\n{\nif (($i &amp; 1 ) == 0 )\n{\n$hash ^= (($hash &lt;&lt;7 ) ^ ord($str[$i]) ^ ($hash&gt;&gt; 3 ));\n}\nelse\n{\n$hash ^= ( ~ (($hash &lt;&lt;11 ) ^ ord($str[$i]) ^ ($hash&gt;&gt; 5)));\n}\n}\nreturn $hash % 701819;\n}\n\nfunction DEKHash($str) \/\/ 0.23\n{\n$n = strlen($str);\n$hash = $n;\nfor ($i = 0; $i &lt;$n; $i++)\n{\n$hash = (($hash &lt;&lt;5) ^ ($hash&gt;&gt; 27)) ^ ord($str[$i]);\n}\nreturn $hash % 701819;\n}\n\nfunction FNVHash($str) \/\/ 0.31\n{\n$hash = 0;\n$n = strlen($str);\nfor ($i = 0; $i &lt;$n; $i++)\n{\n$hash *= 0x811C9DC5;\n$hash ^= ord($str[$i]);\n}\nreturn $hash % 701819;\n}\n\nfunction PJWHash($str) \/\/ 0.33\n{\n$hash = $test = 0;\n$n = strlen($str);\nfor ($i = 0; $i &lt;$n; $i++)\n{\n$hash = ($hash &lt;&lt;4) + ord($str[$i]);\nif(($test = $hash &amp; -268435456)  != 0)\n{\n$hash = (( $hash ^ ($test&gt;&gt; 24)) &amp; (~-268435456));\n}\n}\nreturn $hash % 701819;\n}\n\nfunction PHPHash($str) \/\/ 0.34\n{\n$hash = 0;\n$n = strlen($str);\nfor ($i = 0; $i &lt;$n; $i++)\n{\n$hash = ($hash &lt;&lt;4) + ord($str[$i]);\nif (($g = ($hash &amp; 0xF0000000)))\n{\n$hash = $hash ^ ($g&gt;&gt; 24);\n$hash = $hash ^ $g;\n}\n}\nreturn $hash % 701819;\n}\n\nfunction OpenSSLHash($str) \/\/ 0.22\n{\n$hash = 0;\n$n = strlen($str);\nfor ($i = 0; $i &lt;$n; $i++)\n{\n$hash ^= (ord($str[$i]) &lt;&lt;($i &amp; 0x0f));\n}\nreturn $hash % 701819;\n}\n\nfunction MD5Hash($str) \/\/ 0.050\n{\n$hash = md5($str);\n$hash = $hash[0] | ($hash[1] &lt;&lt;8 ) | ($hash[2] &lt;&lt;16) | ($hash[3] &lt;&lt;24) | ($hash[4] &lt;&lt;32) | ($hash[5] &lt;&lt;40) | ($hash[6] &lt;&lt;48) | ($hash[7] &lt;&lt;56);\nreturn $hash % 701819;\n}\n\n?&gt;<\/pre>\n<p>&nbsp;<br \/>\n\u539f\u4f5c\u8005\u8bf4md5hash\u7684\u6548\u7387\u6700\u9ad8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php function DJBHash($str) \/\/ 0.22 { $hash = 0; $n [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=101"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":448,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/101\/revisions\/448"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}