{"id":100,"date":"2012-04-10T17:34:41","date_gmt":"2012-04-10T09:34:41","guid":{"rendered":"http:\/\/www.freezhongzi.info\/?p=100"},"modified":"2019-09-29T09:39:22","modified_gmt":"2019-09-29T01:39:22","slug":"hash%e7%ae%97%e6%b3%95%e7%9a%84%e7%a2%b0%e6%92%9e%e6%a6%82%e7%8e%87","status":"publish","type":"post","link":"https:\/\/bl4kraven.com\/index.php\/2012\/04\/10\/hash%e7%ae%97%e6%b3%95%e7%9a%84%e7%a2%b0%e6%92%9e%e6%a6%82%e7%8e%87\/","title":{"rendered":"Hash\u7b97\u6cd5\u7684\u78b0\u649e\u6982\u7387"},"content":{"rendered":"<h3>Hash\u7b97\u6cd5\u7684\u7528\u9014<\/h3>\n<ul>\n<li><em>\u4ea7\u751f\u5168\u5c40\u552f\u4e00\u6807\u8bc6<\/em> \u5c3d\u7ba1\u4e0d\u53ef\u80fd\uff0c\u4e0d\u8fc7\u5c0f\u8303\u56f4\u5185\u53ef\u884c\uff0c\u4e0b\u9762\u4f1a\u8ba8\u8bba\u3002<\/li>\n<li><em>\u6821\u9a8c\u548c(Checksum)<\/em> \u5176\u5b9eChecksum\u548cHash\u8fd8\u662f\u6709\u533a\u522b\u7684\uff0c\u770b<a href=\"https:\/\/www.codinghorror.com\/blog\/2005\/04\/checksums-and-hashes.html\">\u8fd9\u91cc<\/a>\u3002<\/li>\n<li><em>\u5bc6\u7801\u5b89\u5168<\/em> \u4e00\u822c\u4e3b\u8981\u7528\u6765\u505a\u5bc6\u7801\u7684\u7b7e\u540d\uff0c\u4f8b\u5982\u5728\u6570\u636e\u5e93\u91cc\u5b58\u653eMD5\u540e\u7684\u5bc6\u7801\u3002\u5982\u679c\u8981\u4fdd\u8bc1\u5bc6\u7801\u7684\u5b89\u5168\uff0c\u9632\u6b62\u88ab\u5f69\u8679\u8868\u653b\u51fb\uff0c\u53ef\u4ee5<a href=\"http:\/\/www.adayinthelifeof.nl\/2011\/02\/02\/password-hashing-and-salting\/\">\u52a0\u76d0(Salt)<\/a>\u3002<\/li>\n<li><em>Hash\u8868\u7d22\u5f15<\/em> \u8fd9\u4e2a\u5e94\u8be5\u6700\u5e38\u7528\u7684\u3002<\/li>\n<\/ul>\n<p>Hash\u7b97\u6cd5\u968f\u7528\u9014\u7684\u4e0d\u540c\u800c\u4e0d\u540c\uff0c\u4f8b\u5982\u6821\u9a8c\u548c(Checksum)Hash\u7b97\u6cd5\u9700\u8981\u5c3d\u91cf\u9ad8\u6548\u3001\u5feb\u901f(\u5982CRC)\uff0c\u800c\u5728\u5bc6\u7801\u5b89\u5168\u662f\u5219\u5fc5\u987b\u4f4e\u6548\u3001\u7f13\u6162\u4ece\u800c\u907f\u514d\u88ab\u66b4\u529b\u7834\u89e3(\u5982MD5\u3001SHA-1\u7b49)\u3002<\/p>\n<p>\u7406\u60f3\u4e2d\u7684Hash\u7b97\u6cd5\u7684\u4e00\u4e2a\u5171\u540c\u7279\u70b9\u90a3\u5c31\u662f\u4ea7\u751f\u7684\u503c\u662f\u968f\u673a\u548c\u552f\u4e00\u7684\uff0c\u4f46\u6839\u636e\u9e3d\u5b50\u7a9d\u539f\u7406(<a href=\"https:\/\/en.wikipedia.org\/wiki\/Pigeonhole_principle\">pigeonhole principle<\/a>)\u8fd9\u662f\u4e0d\u53ef\u80fd\u7684\uff0c\u4f46\u662f\u78b0\u649e\u53d1\u751f\u7684\u6982\u7387\u5927\u4f53\u662f\u600e\u4e48\u5206\u522b\u7684\u5462\uff1f<\/p>\n<h3>\u751f\u65e5\u6096\u8bba<\/h3>\n<p>\u8fd9\u4e2aHash\u7684\u78b0\u649e\u95ee\u9898\u5176\u5b9e\u4e0e<a href=\"https:\/\/en.wikipedia.org\/wiki\/Birthday_paradox\">\u751f\u65e5\u6096\u8bba(Birthday problem)<\/a>\u4e00\u6837\uff1a<\/p>\n<pre><code>    \u5982\u679c\u4e00\u4e2a\u73ed\u7ea7\u4e0a\u670930\u4e2a\u540c\u5b66\uff0c\u5219\u81f3\u5c11\u51fa\u73b0\u4e24\u4e2a\u4eba\u540c\u751f\u65e5\u7684\u6982\u7387\u662f\u591a\u5c11\uff1f\uff08\u5047\u8bbe\u4e0d\u8003\u8651\u95f0\u5e74\uff0c\u4e00\u5e74365\u5929\uff09\n<\/code><\/pre>\n<p>\u5f52\u7eb3\u4e00\u4e0b\u95ee\u9898\u53d8\u6210\uff1a<\/p>\n<pre><code>    \u5047\u8bbe\u4ece\u96c6\u5408m\u4e2d\u53d6n\u4e2a(n &gt; 0, n &lt;= m)\uff0c\u5219\u53d6\u51fa\u76f8\u540c\u7684\u6982\u7387\u662f\u591a\u5c11\uff1f\n<\/code><\/pre>\n<p>\u7528\u9ad8\u4e2d\u7684\u7ec4\u5408\u6570\u5b66\u5f97\u5230\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/bl4kraven.com\/pic\/Hash1.gif\" alt=\"\u516c\u5f0f1\"><\/p>\n<p>\u56e0\u4e3ak\/m\u8fdc\u8fdc\u5c0f\u4e8e1\uff08k\u4e3a30\uff0cm\u4e3a365\uff09\uff0c\u53ef\u4ee5\u7528\u6cf0\u52d2\u7ea7\u6570\u7684\u4e00\u7ea7\u8fd1\u4f3c\u8868\u793a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/bl4kraven.com\/pic\/Hash3.gif\" alt=\"\u516c\u5f0f2\"><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/bl4kraven.com\/pic\/Hash4.gif\" alt=\"\u516c\u5f0f3\"><\/p>\n<p>\u6700\u540e\u5f97\u5230\u7ed3\u679c\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/bl4kraven.com\/pic\/Hash2.gif\" alt=\"\u516c\u5f0f4\"><\/p>\n<p>\u8fd9\u6837\u53ef\u4ee5\u7b97\u51fa\u751f\u65e5\u6096\u8bba\u91cc\u7684\u6982\u7387\u6765\uff1a<\/p>\n<pre><code>    30\u4e2a\u4eba\u4e2d\u6709\u540c\u751f\u65e5\u7684\u6982\u7387P(30) = 70%\n    70\u4e2a\u4eba\u4e2d\u6709\u540c\u751f\u65e5\u7684\u6982\u7387P(70) = 99% \uff08\u8fd9\u4e2a\u8db3\u591f\u8ba9\u4eba\u60ca\u8bb6\u4e86\uff0c\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u53eb\u6096\u8bba\u7684\u539f\u56e0\u4e86:)\uff09\n<\/code><\/pre>\n<p>\u6982\u7387\u7684\u5206\u5e03\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/e\/e7\/Birthday_Paradox.svg\/500px-Birthday_Paradox.svg.png\" width=\"450\" height=\"281\"><\/p>\n<h3>Hash\u7b97\u6cd5\u7684\u78b0\u649e\u6982\u7387<\/h3>\n<p>\u5047\u8bbeHash\u7b97\u6cd5\u662f\u968f\u673a\u7684\uff0c\u6839\u636e\u4ee5\u524d\u7684\u516c\u5f0f\u5f97\u5230\u78b0\u649e\u7684\u6982\u7387P(m,n)\uff0cm\u4ee3\u8868Hash\u4ea7\u751f\u7684\u4e2a\u6570\uff08\u4e00\u822c\u4e3a2^n\uff0cMD5\u4e3a128\u4f4d\uff0c\u6240\u4ee5\u4e3a2^128\uff09\uff0cn\u4e3a\u8fde\u7eedHash\u7684\u6b21\u6570\uff0c\u5f53n\u503c\u8fdc\u5c0f\u4e8eM\u65f6\u7528\u6cf0\u52d2\u7ea7\u6570\u4e00\u7ea7\u8fd1\u4f3c\u5f97\u5230\u7b80\u5316\u7684\u516c\u5f0f\uff1a<\/p>\n<p>P(m,n) = <img decoding=\"async\" src=\"https:\/\/bl4kraven.com\/pic\/Hash5.gif\" alt=\"\u516c\u5f0f5\"><\/p>\n<p>Hash\u591a\u5c11\u6b21\u4ee5\u540e\u78b0\u649e\u7684\u6982\u7387\u4e3a50%\u5462\uff1f\u4e5f\u5c31\u662f\u6839\u636e\u6982\u7387\u548cm\u6c42\u51fan\uff1a<\/p>\n<p>N(p, m) = <img decoding=\"async\" src=\"https:\/\/bl4kraven.com\/pic\/Hash6.gif\" alt=\"\u516c\u5f0f6\"><\/p>\n<pre><code>    16\u4f4dHash\u78b0\u649e\u6982\u7387\u4e3a50%\uff0c\u5219n = 301\u6b21\n    32\u4f4dHash\u78b0\u649e\u6982\u7387\u4e3a50%\uff0c\u5219n = 77162\u6b21\n    128\u4f4dMD5\u78b0\u649e\u6982\u7387\u4e3a50%\uff0c\u5219n = 21,719,381,355,163,562,492\u6b21\n<\/code><\/pre>\n<h2>\u53c2\u8003<\/h2>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Birthday_paradox\">http:\/\/en.wikipedia.org\/wiki\/Birthday_paradox<\/a><\/p>\n<p><a href=\"http:\/\/www.codinghorror.com\/blog\/2007\/12\/hashtables-pigeonholes-and-birthdays.html\">http:\/\/www.codinghorror.com\/blog\/2007\/12\/hashtables-pigeonholes-and-birthdays.html<\/a><\/p>\n<p><a href=\"http:\/\/www.codinghorror.com\/blog\/2012\/04\/speed-hashing.html\">http:\/\/www.codinghorror.com\/blog\/2012\/04\/speed-hashing.html<\/a><\/p>\n<p><a href=\"http:\/\/www.skrenta.com\/2007\/08\/md5_tutorial.html\">http:\/\/www.skrenta.com\/2007\/08\/md5_tutorial.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hash\u7b97\u6cd5\u7684\u7528\u9014 \u4ea7\u751f\u5168\u5c40\u552f\u4e00\u6807\u8bc6 \u5c3d\u7ba1\u4e0d\u53ef\u80fd\uff0c\u4e0d\u8fc7\u5c0f\u8303\u56f4\u5185\u53ef\u884c\uff0c\u4e0b\u9762\u4f1a\u8ba8\u8bba\u3002 &hellip; <a href=\"https:\/\/bl4kraven.com\/index.php\/2012\/04\/10\/hash%e7%ae%97%e6%b3%95%e7%9a%84%e7%a2%b0%e6%92%9e%e6%a6%82%e7%8e%87\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a> <a href=\"https:\/\/bl4kraven.com\/index.php\/2012\/04\/10\/hash%e7%ae%97%e6%b3%95%e7%9a%84%e7%a2%b0%e6%92%9e%e6%a6%82%e7%8e%87\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-program"],"_links":{"self":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":4,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":560,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/100\/revisions\/560"}],"wp:attachment":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}