{"id":1166,"date":"2025-12-01T22:47:48","date_gmt":"2025-12-01T14:47:48","guid":{"rendered":"https:\/\/blog.guguan.us.kg\/?p=1166"},"modified":"2026-04-22T01:41:18","modified_gmt":"2026-04-21T17:41:18","slug":"%e6%95%b0%e5%ad%97%e5%93%88%e5%b8%8c%e5%99%a8","status":"publish","type":"post","link":"https:\/\/blog.guguan.us.kg\/?p=1166","title":{"rendered":"\u6570\u5b57\u54c8\u5e0c\u5668\uff08\u975e\u5bc6\u7801\u5b66\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5c06\u4e00\u4e32\u6570\u5b57\u8f6c\u4e3a\u4e00\u4e326\u4f4d\u6570\u5b57\u2026\u6211\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u65e0\u804a\u53c8\u505a\u4e86\u4e00\u4e2a\u6beb\u65e0\u610f\u4e49\u7684\u4e1c\u897f\uff08<\/p>\n\n\n\n<form onsubmit=\"incrementAndDisplay(); return false;\">\n\t<p>\n\t\t<label for=\"numberInput\">\u8f93\u5165\uff1a<\/label>\n\t\t<input type=\"text\" id=\"numberInput\" inputmode=\"numeric\" pattern=\"[0-9]*\" \n\t\t       minlength=\"1\" maxlength=\"20\" placeholder=\"\u8bf7\u8f93\u5165\u6b63\u6574\u6570\" \n\t\t       title=\"\u53ea\u80fd\u8f93\u5165\u6570\u5b57\" autocomplete=\"off\" required>\n\t\t<button type=\"submit\">\u8f6c\u6362<\/button>  <!-- \u6539\u6210 submit \u66f4\u8bed\u4e49\u5316 -->\n\t<\/p>\n\t<p>\n\t\t<label for=\"resultOutput\">\u7ed3\u679c\uff1a<\/label>\n\t\t<input type=\"text\" id=\"resultOutput\" readonly>\n\t<\/p>\n<\/form>\n<script>\n\t\/**\n\t * \u5c06\u8f93\u5165\u7684\u6570\u5b57\u5b57\u7b26\u4e32\u6620\u5c04\u4e3a\u56fa\u5b9a\u957f\u5ea6\u7684\u6570\u5b57\u54c8\u5e0c\uff08\u975e\u52a0\u5bc6\uff09\n\t * @param {string} inputStr \u8f93\u5165\u7684\u6570\u5b57\u5b57\u7b26\u4e32\uff0c\u5982 \"123456789\"\n\t * @param {number} length \u8f93\u51fa\u6570\u5b57\u4f4d\u6570\uff0c\u9ed8\u8ba4 6\n\t * @param {number} salt \u53ef\u9009\u76d0\u503c\uff0c\u7528\u4e8e\u6df7\u6dc6\uff08\u9ed8\u8ba4 0\uff09\n\t * @returns {string} \u957f\u5ea6\u4e3a length \u7684\u6570\u5b57\u5b57\u7b26\u4e32\uff0c\u5982 \"472839\"\n\t *\/\n\tfunction numericHash(inputStr, length = 6, salt = 0) {\n\t\t\/\/ 1. \u8f6c\u4e3a BigInt\uff08\u9632\u6b62\u8d85\u957f\u6570\u5b57\u6ea2\u51fa\uff09\n\t\tlet num = BigInt(inputStr) + BigInt(salt);\n\n\t\t\/\/ 2. \u4e58\u6cd5\u54c8\u5e0c\u5e38\u6570\uff0832\u4f4d\u9ec4\u91d1\u6bd4\u4f8b\uff09\n\t\tconst prime = 0x9e3779b9n;\n\t\tlet hash = (num * prime) & 0xFFFFFFFFn;\n\n\t\t\/\/ 3. \u4e8c\u6b21\u6df7\u5408\n\t\thash = ((hash >> 16n) ^ hash) * 0x45d9f3bn;\n\t\thash = ((hash >> 16n) ^ hash) * 0x45d9f3bn;\n\t\thash = (hash >> 16n) ^ hash;\n\n\t\t\/\/ 4. \u53d6\u6a21\u5e76\u683c\u5f0f\u5316\n\t\tconst max = 10n ** BigInt(length);\n\t\tconst result = hash % max;\n\t\treturn result.toString().padStart(length, \"0\");\n\t}\n\n\t\/\/ \u793a\u4f8b\uff1aconsole.log(numericHash(\"123456789\"));\n\n\tfunction incrementAndDisplay() {\n\t\tconst inputValue = document.getElementById('numberInput').value.trim();\n\n\t\tif (!inputValue) {\n\t\t\talert('\u8bf7\u8f93\u5165\u4e00\u4e2a\u6570\u5b57\uff01');\n\t\t\treturn;\n\t\t}\n\n\t\t\/\/ \u5173\u952e\uff1a\u76f4\u63a5\u7528\u5b57\u7b26\u4e32\uff0c\u4e0d\u8f6c Number\uff01\n\t\tif (!\/^\\d+$\/.test(inputValue)) {\n\t\t\talert('\u53ea\u80fd\u8f93\u5165\u7eaf\u6570\u5b57\uff01');\n\t\t\treturn;\n\t\t}\n\n\t\tif (inputValue.length > 20) {\n\t\t\talert('\u6570\u5b57\u592a\u957f\u4e86\uff01\u6700\u591a\u652f\u630120\u4f4d');\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tdocument.getElementById('resultOutput').value = numericHash(inputValue);\n\t\t} catch (e) {\n\t\t\talert('\u8ba1\u7b97\u51fa\u9519\uff1a' + e.message);\n\t\t}\n\t}\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>\u5c06\u4e00\u4e32\u6570\u5b57\u8f6c\u4e3a\u4e00\u4e326\u4f4d\u6570\u5b57\u2026\u6211\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u65e0\u804a\u53c8\u505a\u4e86\u4e00\u4e2a\u6beb\u65e0\u610f\u4e49\u7684\u4e1c\u897f\uff08 \u8f93\u5165\uff1a \u8f6c\u6362 \u7ed3\u679c\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[140],"class_list":["post-1166","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-tools"],"_links":{"self":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/1166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1166"}],"version-history":[{"count":9,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/1166\/revisions"}],"predecessor-version":[{"id":1208,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/1166\/revisions\/1208"}],"wp:attachment":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}