{"id":433,"date":"2020-12-13T00:28:22","date_gmt":"2020-12-12T16:28:22","guid":{"rendered":"http:\/\/moyisuiying.com\/?p=433"},"modified":"2020-12-13T00:28:22","modified_gmt":"2020-12-12T16:28:22","slug":"%e4%bf%a1%e6%81%af%e6%91%98%e8%a6%81%e5%87%bd%e6%95%b0hash%e5%87%bd%e6%95%b0%e7%9a%84%e8%ae%be%e8%ae%a1%e4%b8%8e%e6%80%a7%e8%b4%a8%e9%aa%8c%e8%af%81","status":"publish","type":"post","link":"http:\/\/moyisuiying.com\/index.php\/cppstudy\/information-secure\/433.html","title":{"rendered":"\u4fe1\u606f\u6458\u8981\u51fd\u6570(Hash\u51fd\u6570)\u7684\u8bbe\u8ba1\u4e0e\u6027\u8d28\u9a8c\u8bc1"},"content":{"rendered":"\n<h2>1.\u4fe1\u606f\u6458\u8981\u51fd\u6570(Hash\u51fd\u6570)\u7684\u8bbe\u8ba1\u4e0e\u6027\u8d28\u9a8c\u8bc1\u5b9e\u9a8c<\/h2>\n\n\n\n<h2>2.\u5b9e\u9a8c\u76ee\u7684\uff1a\u4fe1\u606f\u6458\u8981\u51fd\u6570(Hash\u51fd\u6570)\u7684\u8bbe\u8ba1\u4e0e\u6027\u8d28\u9a8c\u8bc1\u3002<\/h2>\n\n\n\n<h3>2.1\u5b9e\u9a8c\u8bbe\u5907\uff1aPC\u673a \u4e00\u53f0\/\u4eba<\/h3>\n\n\n\n<h3>2.2\u5b9e\u9a8c\u539f\u7406\uff1a<\/h3>\n\n\n\n<h4>2.2.1.\u4fe1\u606f\u6458\u8981\u51fd\u6570\u5177\u6709\u56fa\u5b9a\u7684\u8f93\u51fa\u6570\u4f4d\u3002<\/h4>\n\n\n\n<h4>2.2.1\u4fe1\u606f\u6458\u8981\u51fd\u6570\u6ee1\u8db3\u4e0d\u53ef\u6c42\u9006\uff0c\u4e0d\u53ef\u4f2a\u9020\u548c\u5728\u53ef\u884c\u65f6\u95f4\u4e4b\u5185\u627e\u4e0d\u5230\u78b0\u649e\u7b49\u7279\u6027\u3002<\/h4>\n\n\n\n<h2>3.\u5b9e\u9a8c\u5185\u5bb9\u53ca\u6ce8\u610f\u4e8b\u9879\uff1a<\/h2>\n\n\n\n<p>\u4fe1\u606f\u6458\u8981\u51fd\u6570\u7684\u8bbe\u8ba1\u4e0eHash\u503c\u7684\u6027\u8d28\u9a8c\u8bc1<\/p>\n\n\n\n<p>\u5b9e\u9a8c\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<h3>3.1\u8bbe\u8ba1\u7b26\u5408\u539f\u7406\u8981\u6c42\u7684\u4fe1\u606f\u6458\u8981\u51fd\u6570H(m)\u3002<\/h3>\n\n\n\n<h3>3.2\u5bf9\u4e8e\u5982\u4e0b\u660e\u6587\u4fe1\u606fm:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>There was a grocery shop in a town. Plenty of mice lived in that grocery shop. Food was in plenty for them. They ate everything and spoiled all the bags. They also wasted the bread, biscuits and fruits of the shop. The grocer got really worried. So, he thought \"I should buy a cat and let it stay at the grocery. Only then I can save my things.\" He bought a nice, big fat cat and let him stay there. The cat had a nice time hunting the mice and killing them. The mice could not move freely now. They were afraid that anytime the cat would eat them up. The mice wanted to do something. They held a meeting and all of them tweeted \"We must get rid of the cat. Can someone give a suggestion\"?  All the mice sat and brooded. A smart looking mouse stood up and said, \"The cat moves softly. That is the problem. If we can tie a bell around her neck, then things will be fine. We can know the movements of the cat\". \u201cYes, that is answer,\" stated all the mice. An old mouse slowly stood up and asked, \"Who would tie the bell?\" After some moments there was no one there to answer this question. <\/code><\/pre>\n\n\n\n<p>\u8c03\u7528H(m)\u7b97\u6cd5\uff0c\u4ea7\u751fHash\u503c\u3002<\/p>\n\n\n\n<h3>3.3\u968f\u673a\u6539\u53d8m\u7684\u4efb\u610f\u4e00\u4f4d\u5b57\u7b26\uff0c\u4ea7\u751f\u65b0\u7684Hash\u503c\uff0c<\/h3>\n\n\n\n<p>\u5982\u6b64\u5b9e\u9a8c10\u6b21\uff0c\u8bb0\u65b0\u7684Hash\u503c\u4e3a H1,H2,\u2026H10<\/p>\n\n\n\n<h3>3.4\u8bbe\u8ba1\u51fd\u6570\u8ba1\u7b97H0\u548cHi \u7684\u76f8\u4f3c\u5ea6 i=1,2,\u202610<\/h3>\n\n\n\n<h3>3.5\u5206\u6790\u7ed3\u679c\uff0c\u5f97\u51fa\u7ed3\u8bba<\/h3>\n\n\n\n<h2>4.\u5b9e\u9a8c\u8fc7\u7a0b<\/h2>\n\n\n\n<h3>4.1\u8bbe\u8ba1 \u54c8\u5e0c\u51fd\u6570Hash(m)\u7684\u601d\u8def<\/h3>\n\n\n\n<p>\u200b <strong>MD5<\/strong>\u6458\u8981\u7b97\u6cd5\u662fHash\u6458\u8981\u7b97\u6cd5\u4e2d\u7684\u4e00\u79cd\u6458\u8981\u7b97\u6cd5\uff0c\u5177\u6709<strong>\u4e0d\u53ef\u6c42\u9006\u6027\uff0c\u4e0d\u53ef\u4f2a\u9020\u6027<\/strong>\u3002MD5 \u7b97\u6cd5\u81ea\u8bde\u751f\u4e4b\u65e5\u8d77\uff0c\u5c31\u6709\u5f88\u591a\u4eba\u8bd5\u56fe\u8bc1\u660e\u548c\u53d1\u73b0\u5b83\u7684\u4e0d\u5b89\u5168\u4e4b\u5904\uff0c\u5373\u5b58\u5728\u78b0\u649e\uff08\u5728\u5bf9\u4e24\u4e2a\u4e0d\u540c\u7684\u5185\u5bb9\u4f7f\u7528 MD5\u7b97\u6cd5\u8fd0\u7b97\u7684\u65f6\u5019\uff0c\u6709\u53ef\u80fd\u5f97\u5230\u4e00\u5bf9\u76f8\u540c\u7684\u7ed3\u679c\u503c\uff09\u30022009\u5e74\uff0c\u4e2d\u56fd\u79d1\u5b66\u9662\u7684\u8c22\u6d9b\u548c\u51af\u767b\u56fd\u4ec5\u7528\u4e86 \u7684\u78b0\u649e\u7b97\u6cd5\u590d\u6742\u5ea6\uff0c\u7834\u89e3\u4e86MD5\u7684\u78b0\u649e\u62b5\u6297\uff0c\u8be5\u653b\u51fb\u5728\u666e\u901a\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u53ea\u9700\u8981\u6570\u79d2\u949f \u3002\u56e0\u6b64MD5\u7b97\u6cd5\u4e0d\u5177\u5907\u5b9e\u9a8c\u4e2d\u8981\u6c42\u7684\u201c\u5728\u53ef\u884c\u65f6\u95f4\u4e4b\u5185\u627e\u4e0d\u5230\u78b0\u649e\u201d\u8fd9\u4e2a\u7279\u6027\u3002<br>\u200b \u6839\u636eMD5\u7684\u5b58\u5728\u7684\u7f3a\u70b9\uff0c\u4e3a\u4e86\u52a0\u5f3aMD5\u52a0\u5bc6\u7b97\u6cd5\u7684\u5b89\u5168\u6027\uff08\u672c\u8eab\u662f\u4e0d\u53ef\u9006\u7684\uff09\uff0c\u4ece\u800c\u52a0\u5165\u4e86\u65b0\u7684\u7b97\u6cd5\u90e8\u5206\u5373\u52a0\u76d0\u503c\uff0c\u52a0\u76d0\u503c\u662f\u968f\u673a\u751f\u6210\u7684\u4e00\u7ec4\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u5305\u62ec\u968f\u673a\u7684\u5927\u5c0f\u5199\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u5b57\u7b26\uff0c\u4f4d\u6570\u53ef\u4ee5\u6839\u636e\u8981\u6c42\u800c\u4e0d\u4e00\u6837\uff0c\u4f7f\u7528\u4e0d\u540c\u7684\u52a0\u76d0\u503c\u4ea7\u751f\u7684\u6700\u7ec8\u5bc6\u6587\u662f\u4e0d\u4e00\u6837\u7684\u3002\u7531\u4e8e\u4f7f\u7528\u52a0\u76d0\u503c\u4ee5\u540e\u7684\u5bc6\u7801\u76f8\u5f53\u7684\u5b89\u5168\uff0c\u5373\u4fbf\u662f\u4f60\u83b7\u5f97\u4e86\u5176\u4e2d\u7684salt\u548c\u6700\u7ec8\u5bc6\u6587\uff0c\u7834\u89e3\u4e5f\u662f\u4e00\u4e2a\u8017\u8d39\u76f8\u5f53\u591a\u65f6\u95f4\u7684\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u8bf4\u662f\u7834\u89e3\u5355\u7eafMD5\u7684\u597d\u51e0\u500d\u3002\u5e76\u4e14\u540c\u4e00\u4e2a\u660e\u6587\u5728\u7ecf\u8fc7\u52a0\u76d0\uff08\u8fd9\u4e2a\u76d0\u662f\u968f\u673a\u7684\uff0c\u4e0d\u540c\u7684\uff09\u540e\u8fdb\u884cMD5\u7b97\u6cd5\u4ea7\u751f\u7684\u5bc6\u6587\u4e5f\u662f\u4e0d\u540c\u7684\u3002\u8fd9\u5c31\u4f7f\u5f97MD5\u7b97\u6cd5\u7684\u6297\u78b0\u649e\u6027\u5f97\u5230\u5927\u5e45\u5ea6\u589e\u5f3a\uff0c\u56e0\u6b64\u53ef\u4ee5\u6ee1\u8db3\u672c\u6b21\u5b9e\u9a8c\u8981\u6c42\u3002<\/p>\n\n\n\n<h3>4.2MD5+\u76d0\u7684\u5b9e\u73b0\u6b65\u9aa4<\/h3>\n\n\n\n<p>1).\u9996\u5148\u83b7\u53d6\u9700\u8981\u8fdb\u884cmd5\u666e\u6458\u8981\u7b97\u6cd5\u7684\u660e\u6587text\u3002<br>2).\u968f\u673a\u751f\u6210\u52a0\u76d0\u503c\uff08\u53ef\u4ee5\u7531\u5b57\u6bcd\uff0c\u6570\u5b57\uff0c\u5b57\u7b26\u7ec4\u6210\uff0c\u4f4d\u6570\u53ef\u4ee5\u81ea\u5df1\u51b3\u5b9a\uff0c\u8fd9\u91cc\u4f7f\u752816\u4f4d\u7684\u5b57\u7b26\u4e32\uff09salt\u5b57\u7b26\u4e32.<br>3)\u5c06\u751f\u6210\u7684salt\u5b57\u7b26\u4e32\u8ffd\u52a0\u5230\u660e\u6587text\u4e2d\uff0c\u5f97\u5230\u7ec4\u5408\u7684\u5b57\u7b26\u4e32 mergeText = text +salt<br>4\uff09\u4f7f\u7528md5\u666e\u901a\u6458\u8981\u7b97\u6cd5\u83b7\u53d6mergeText \u7684hash\u503c\u5f97\u5230\u4e00\u4e2a32\u4f4d\u7684\u5b57\u7b26\u4e32decodeText\u3002<br>5).\u5c06\u76d0salt\u5b57\u7b26\u4e32\u7684\u6bcf\u4e2a\u5b57\u7b26\u9010\u4e2a\u63d2\u5165\u5230\u5b57\u7b26\u4e32decodeText\u662f i *3+1\uff08i = 0,1,2,\u202616\uff09\u7684\u4f4d\u7f6e\u4e0a,\u5f97\u5230\u4e00\u4e2a\u65b0\u768448\u4f4d\u7684\u5b57\u7b26\u4e32 decode\u3002<br>6\uff09\u6700\u7ec8\u7684decode\u5b57\u7b26\u4e32\u5c31\u662f\u6240\u8981\u7684\u5bc6\u6587\uff0c\u4f4d\u957f\u4e3a48\u4e2a\u5b57\u7b26\u3002<\/p>\n\n\n\n<p>\u8be5\u4ee3\u7801\u5df2\u7ecf\u7528c++\u5b9e\u73b0\uff0c\u5177\u4f53\u8bf7\u770b\uff1a<a href=\"http:\/\/moyisuiying.com\/index.php\/cppstudy\/information-secure\/429.htmlhttp:\/\/moyisuiying.com\/index.php\/cppstudy\/information-secure\/429.html\">C++<\/a><a href=\"https:\/\/blog.csdn.net\/u011870022\/article\/details\/111086628\" target=\"_blank\"  rel=\"nofollow\" >\u5b9e\u73b0MD5\u6458\u8981\u7b97\u6cd5\u52a0\u76d0salt\u503c<\/a><\/p>\n\n\n\n<h3>4.3\u5177\u4f53\u4ee3\u7801\u5b9e\u73b0<\/h3>\n\n\n\n<h4>4.3.1MD5\u7684\u666e\u901a\u52a0\u5bc6\u7b97\u6cd5<\/h4>\n\n\n\n<h5>4.3.1.1.\u5c06\u4e8c\u8fdb\u5236\u5b57\u8282\u6570\u7ec4\u8f6c\u6362\u4e3a16\u8fdb\u5236\u7684\u5b57\u7b26\u4e32<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* Convert byte array to hex string. *\/\nstring MD5::bytesToHexString(const byte *input, size_t length) {\n    string str;\n    str.reserve(length &lt;&lt; 1);\n    for (size_t i = 0; i &lt; length; i++) {\n        int t = input&#91;i];\n        int a = t \/ 16;\n        int b = t % 16;\n        str.append(1, HEX&#91;a]);\n        str.append(1, HEX&#91;b]);\n    }\n    return str;\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>string EncryptUtil::md5Hex(const string&amp; text) {\n    \/\/\u9996\u5148\u66f4\u65b0md5\u4e2d\u9700\u8981\u8fdb\u884c\u6458\u8981\u7684\u5b57\u7b26\u4e32\n    this->md5->update(text);\n    \/\/\u4f7f\u7528md5\u7684\u65b9\u6cd5\u751f\u6210\u5bf9\u5e94\u7684\u6458\u8981\u540e\u7684\u5b57\u7b26\u4e32\n    return this->md5->toString();\n\n}<\/code><\/pre>\n\n\n\n<h4>4.3.2\u4ea7\u751f\u76d0\u503c\u5b57\u7b26\u4e32\u7684\u7b97\u6cd5<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n\u4ea7\u751f\u76d0\u503c\u5b57\u7b26\u4e32salt\n*\/\nstring EncryptUtil::createSalt()\n{\n    \/\/\u968f\u673a\u751f\u6210\u4e24\u4e2a\u968f\u673a\u6570\n    int num1 = rand() % 99999999;\n    int num2 = rand() % 99999999;\n    string salt = \"\";\n    \/\/\u5c06\u8fd9\u4e24\u4e2a\u968f\u673a\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u540e\u8ffd\u52a0\u5230salt\u4e2d\n    salt.append(to_string(num1));\n    salt.append(to_string(num2));\n    \/\/salt\u4e0d\u591f\u5341\u516d\u4f4d\u5c31\u5728\u540e\u9762\u52a00\n    int len = salt.size();\n    if (len &lt; 16) {\n        for (int i = 0; i &lt; 16 - len; i++) {\n            salt.append(\"0\");\n        }\n    }\n    return salt;\n}<\/code><\/pre>\n\n\n\n<h4>4.3.3\u83b7\u53d6md5\u666e\u901a\u6458\u8981\u51fd\u6570+\u76d0\u503csalt\u64cd\u4f5c\u540e\u7684\u6700\u7ec8\u5bc6\u6587<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n* \u52a0\u76d0MD5\n* @param text : \u9700\u8981\u8fdb\u884c\u52a0\u76d0\u540e\u6458\u8981\u7684text\u660e\u6587\n* @return string\uff1a\u8fd4\u56de\u8fdb\u884c\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5b57\u7b26\u4e32\n*\/\nstring EncryptUtil::encryptBySalt(const string&amp; text) {\n    \/\/\u4ea7\u751f\u76d0\u503c\u5b57\u7b26\u4e32salt\n    string salt = createSalt();\n    \/\/\u5c06\u4ea7\u751f\u7684salt\u8ffd\u52a0\u5230\u9700\u8981\u8fdb\u884c\u6458\u8981\u7684\u660e\u6587text\u4e2d\uff0c\u5f97\u5230\u7531\u660e\u6587text\u548csalt\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\n    string merge_str =  text + salt;\n    \/\/\u4f7f\u7528md5\u7b97\u6cd5\u8fdb\u884c\u6458\u8981\u8ba1\u7b97\u5f97\u5230\u76f8\u5e94\u768432\u4f4d\u7684\u5bc6\u6587\n    string encodeText = md5Hex(merge_str);\n    char cs &#91;48];\n    \/\/\u5c0632\u4f4d\u7684\u5bc6\u6587\u548c\u4ea7\u751f\u768416\u4f4d\u7684salt\u8fdb\u884c\u91cd\u7ec4\u5f62\u6210\u65b0\u768448\u4f4d\u7684\u5b57\u7b26\u4e32\u3002\n    \/\/\u8fd9\u91cc\u8868\u793a\uff0c\u5728\u65b0\u7684\u5b57\u7b26\u6570\u7ec4cs\u4e2d\uff0csalt\u4e2d\u7684\u5b57\u7b26\u6dfb\u52a0\u5230cs\u5b57\u7b26\u6570\u7ec4\u4e2d\u4f4d\u7f6e\u662fi*3+1\u7684\u4f4d\u7f6e\uff0c\u5176\u5b83\u4f4d\u7f6e\u7531\u6458\u8981\u5bc6\u6587encodeText\u4e2d\u7684\u5b57\u7b26\u586b\u5145\n    for (int i = 0; i &lt; 48; i += 3) {\n        cs&#91;i] = encodeText&#91;i \/ 3 * 2];\n        char c = salt&#91;i \/ 3];\n        cs&#91;i + 1] = c;\n        cs&#91;i + 2] = encodeText&#91;i \/ 3 * 2 + 1];\n    }\n    \/\/\u5c06\u7ec4\u5408\u6210\u7684cs\u5b57\u7b26\u6570\u7ec4\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u5f97\u523048\u4f4d\u7684\u52a0\u76d0\u540e\u5f62\u6210\u7684md5\u6458\u8981\u5bc6\u6587\n    string code = \"\";\n    for (int i = 0; i &lt; 48; i++)\n    {\n      code.append(1,cs&#91;i]);\n    }\n    return code;\n}<\/code><\/pre>\n\n\n\n<h4>4.3.4\u6821\u9a8c\u52a0\u76d0\u540e\u662f\u5426\u548c\u539f\u6587\u4e00\u81f4<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * \u6821\u9a8c\u52a0\u76d0\u540e\u662f\u5426\u548c\u539f\u6587\u4e00\u81f4\n * @param text : \u8fdb\u884c\u6458\u8981\u7b97\u6cd5\u7684\u660e\u6587\n * @param encryptText  \uff1a \u8fdb\u884c\u52a0\u76d0\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5bc6\u6587\n * @return \u5982\u679c\u52a0\u76d0\u540e\u548c\u539f\u660e\u6587text\u4e00\u81f4\u5219\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\n *\/\n bool EncryptUtil::verify( string text,  string encryptText) {\n    char md5Text&#91;32];\n    char salt&#91;16];\n    \/\/\u9996\u5148\u5c06\u52a0\u76d0\u540emd5\u7b97\u6cd5\u6458\u8981\u5f97\u5230\u7684encryptText\u5bc6\u6587\u8fdb\u884c\u62c6\u5206\u6210\u4e00\u4e2a32\u4f4d\u7684\u666e\u901amd5\u6458\u8981\u7b97\u6cd5\u5bc6\u6587md5Text\u548c\u4e00\u4e2a16\u4f4d\u7684\u5b57\u7b26\u4e32salt\u3002\n    \/\/\u8fd9\u91cc\u5c31\u662f\u8fdb\u884csalt\u548cmd5\u6458\u8981\u5bc6\u6587\u5f62\u621048\u4f4d\u65b0\u7684\u5b57\u7b26\u4e32encryptText\u65f6\u7684\u9006\u5411\u64cd\u4f5c\u3002encryptText\u4e2dsalt&#91;i] =  encryptText&#91; 3* i + 1], i = 0,1,2,...16\n    for (int i = 0; i &lt; 48; i += 3) {\n        md5Text&#91;i \/ 3 * 2] = encryptText&#91;i];\n        md5Text&#91;i \/ 3 * 2 + 1] = encryptText&#91;i + 2];\n        salt&#91;i \/ 3] = encryptText&#91;i + 1];\n    }\n    \/\/\u5c06\u62c6\u5206\u768416\u4e2a\u968f\u673a\u5b57\u7b26\u4e32\u8ffdsalt\u52a0\u5230\u660e\u6587text\u4e2d\n    for (int  i = 0; i &lt; 16; i++)\n    {\n        text.append(1,salt&#91;i]);\n    }\n    \/\/\u4f7f\u7528md5\u6458\u8981\u7b97\u6cd5\u8fdb\u884c\u751f\u6210\u5bc6\u6587\u5f97\u5230enCs2\n    string enCs2 = md5Hex(text);\n    \/\/\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\uff0c\u5982\u679c\u76f8\u7b49\u5219\u8fd4\u56detrue\uff0c\u53ea\u8981\u6709\u4e00\u4e2a\u5b57\u7b26\u4e0d\u76f8\u7b49\u5c31\u8fd4\u56defalse\n    for (int i = 0; i &lt; enCs2.size(); i++)\n    {\n        if (enCs2&#91;i] != md5Text&#91;i])\n        {\n            return false;\n        }\n    }\n    return true;\n}<\/code><\/pre>\n\n\n\n<h4>4.3.5 \u9010\u4e2a\u6bd4\u8f83\u4e24\u4e2a\u5bc6\u6587\u76f8\u540c\u4f4d\u7f6e\u4e0a\u5b57\u7b26\u662f\u5426\u76f8\u540c\u6765\u8ba1\u7b97\u4e24\u4e2a\u660e\u6587\u8fdb\u884cmd5\u52a0\u5bc6\u540e\u7684\u76f8\u4f3c\u5ea6\u3002<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n  \u9010\u4e2a\u6bd4\u8f83\u4e24\u4e2a\u5bc6\u6587\u76f8\u540c\u4f4d\u7f6e\u4e0a\u5b57\u7b26\u662f\u5426\u76f8\u540c\u6765\u8ba1\u7b97\u4e24\u4e2a\u660e\u6587\u8fdb\u884cmd5\u52a0\u5bc6\u540e\u7684\u76f8\u4f3c\u5ea6\u3002\n @param str1: md5\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5b57\u7b26\u4e32\n @param str2:md5\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5b57\u7b26\u4e32\n @return double: \u8fd4\u56de\u76f8\u4f3c\u5ea6\n *\/\ndouble EncryptUtil::similarityDegree(const string&amp; str1, const string&amp; str2)\n{\n    if (str1.size() &lt;= 0 &amp;&amp; (str1.size() != str2.size()))\n    {\n        return 0;\n    }\n    int count = 0;\n    \/\/\u7edf\u8ba1\u5bf9\u5e94\u4f4d\u7f6e\u4e0a\u5b57\u7b26\u76f8\u540c\u7684\u4e2a\u6570\n    for (int i = 0; i &lt; str1.size(); i++)\n    {\n        if (str1&#91;i] == str2&#91;i])\n        {\n            count++;\n        }\n    }\n    \/\/\u8ba1\u7b97\u76f8\u4f3c\u5ea6\n    double result = count * 1.0 \/ str1.size();\n    return result;\n}<\/code><\/pre>\n\n\n\n<h4>4.3.6\u4e3a\u4e86\u65b9\u4fbf\uff0c\u5c06\u660e\u6587\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u4f5c\u4e3a\u5b57\u7b26\u4e32<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>string loadTextToString(const string textFilePath) {\n    ifstream* ism = new ifstream(textFilePath,ios::app|ios::binary);\n    if (ism->is_open())\n    {\n        string text = \"\";\n        char ch;\n        while (!ism->eof())\n        {\n            ism->get(ch);\n            text.append(1,ch);\n        }\n        return text;\n    }\n    else {\n        cout &lt;&lt; \"\u6253\u5f00\u6587\u4ef6\u5931\u8d25!\" &lt;&lt; endl;\n        return \"\";\n    }\n}<\/code><\/pre>\n\n\n\n<h2>5.\u9a8c\u8bc1\u5b9e\u9a8c\u5185\u5bb9<\/h2>\n\n\n\n<p>\u8bbe\u8ba1\u51fd\u6570\u9a8c\u8bc1\u83b7\u53d6H0\u5230H10\u7684\u5bc6\u6587\uff0c\u5e76\u8ba1\u7b97\u76f8\u4f3c\u5ea6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>string randomReplace(string text,int index,string replaceChar) {\n    return text.replace(index,1,replaceChar);\n}\nvoid test() {\n    string text = loadTextToString(\"hashtext.txt\");\n    cout &lt;&lt; \"\u9700\u8981\u52a0\u5bc6\u7684\u660e\u6587\u4e3a\uff1a\\n\" &lt;&lt; text &lt;&lt; endl;\n    EncryptUtil util;\n    string md0 = util.encryptBySalt(text);\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH0:\" + md0 &lt;&lt; endl;\n    vector&lt;string> vec;\n    for (int i = 0; i &lt; 10; i++)\n    {\n        \/\/\u66ff\u6362\u5341\u4e2a\u5b57\u7b26\uff0c\u6bcf\u4e2a\u539f\u6765\u7684\u5b57\u7b26+1\n        string  newStr =    randomReplace(text, i * 5,string(1, text&#91;i * 5] + 1));\n        \/\/\u8ba1\u7b97\u6bcf\u4e2a\u66ff\u6362\u540e\u5b57\u7b26\u7684hash\u503c\n         string encodeText =util.encryptBySalt(newStr);\n        vec.push_back(encodeText);\n    }\n    for (size_t i = 0; i &lt; 10; i++)\n    {\n        cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH\"+ to_string(i + 1) + \":\" + vec&#91;i]&lt;&lt; endl;\n    }\n    for (size_t i = 0; i &lt; 10; i++)\n    {\n        \/\/\u8ba1\u7b97H0\u548cH\u7684\u76f8\u4f3c\u5ea6\n        cout &lt;&lt; \"H0\u548cH\" + to_string(i + 1) + \"\u7684\u76f8\u4f3c\u5ea6:\" + to_string(util.similarityDegree(md0, vec&#91;i])) &lt;&lt; endl;\n    }\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img   class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20201213001313149.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"[\u5916\u94fe\u56fe\u7247\u8f6c\u5b58\u4e2d\u2026(img-GMQD1fac-1607789521383)]\"\/><\/figure >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20201213001313149.png?x-oss-process=image\/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTE4NzAwMjI=,size_16,color_FFFFFF,t_70\" alt=\"[\u5916\u94fe\u56fe\u7247\u8f6c\u5b58\u4e2d\u2026(img-GMQD1fac-1607789521383)]\"\/><\/figure><\/noscript>\n\n\n\n<p>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH0:051293435697829a9bc1de2ff8ed0cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH1:061233445697859a2bc8de3ff0ed0cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH2:021203415697819a2bc1de9ff1ed6cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH3:091243475677819a6bc4de1ff3ed0cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH4:031203425687869a4bc8de6ff3ed0cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH5:011253485697809a1bc5de5ff0ed7cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH6:031203485607829a1bc5de3ff6ed6cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH7:031203425617829a1bc5de0ff8ed0cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH8:011293475627869a2bc0de0ff9ed0cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH9:021223425667899a1bc2de7ff0ed0cb0a908706504302100<br>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH10:091293415627829a3bc6de5ff5ed0cb0a908706504302100<br>H0\u548cH1\u7684\u76f8\u4f3c\u5ea6:0.833333<br>H0\u548cH2\u7684\u76f8\u4f3c\u5ea6:0.833333<br>H0\u548cH3\u7684\u76f8\u4f3c\u5ea6:0.812500<br>H0\u548cH4\u7684\u76f8\u4f3c\u5ea6:0.812500<br>H0\u548cH5\u7684\u76f8\u4f3c\u5ea6:0.812500<br>H0\u548cH6\u7684\u76f8\u4f3c\u5ea6:0.812500<br>H0\u548cH7\u7684\u76f8\u4f3c\u5ea6:0.854167<br>H0\u548cH8\u7684\u76f8\u4f3c\u5ea6:0.833333<br>H0\u548cH9\u7684\u76f8\u4f3c\u5ea6:0.812500<br>H0\u548cH10\u7684\u76f8\u4f3c\u5ea6:0.854167<\/p>\n\n\n\n<h2>6.\u62d3\u5c55<\/h2>\n\n\n\n<h3>6.1\u9a8c\u8bc1md5\u7ecf\u8fc7\u6458\u8981\u7b97\u6cd5\u540e\u548c\u539f\u6765\u660e\u6587\u4e00\u81f4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>void test9() {\n    string text = loadTextToString(\"hashtext.txt\");\n    EncryptUtil util;\n    string encodeText = util.encryptBySalt(text);\n    string encodeText1 = util.encryptBySalt(text);\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503c:\" + encodeText &lt;&lt; endl;\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503c:\" + encodeText1 &lt;&lt; endl;\n    if (encodeText.compare(encodeText1) == 0)\n    {\n        cout &lt;&lt; \"\u4e24\u6b21\u751f\u6210\u7684\u52a0\u76d0\u5bc6\u6587\u76f8\u7b49\uff01\" &lt;&lt; endl;\n    }\n    else {\n        cout &lt;&lt; \"\u4e24\u6b21\u751f\u6210\u7684\u52a0\u76d0\u5bc6\u6587\u4e0d\u76f8\u7b49\uff01\" &lt;&lt; endl;\n    }\n    bool fla = util.verify(text, encodeText);\n    if (fla == true)\n    {\n        cout &lt;&lt; \"\u539f\u6765\u7684\u660e\u6587\u548c\u52a0\u76d0\u540e\u7684\u660e\u6587\u4e00\u81f4\u5f97\u5230\u9a8c\u8bc1!\" &lt;&lt; endl;\n    }\n    else {\n        cout &lt;&lt; \"\u539f\u6765\u7684\u660e\u6587\u548c\u52a0\u76d0\u540e\u7684\u660e\u6587\u4e0d\u4e00\u81f4!\" &lt;&lt; endl;\n    }\n\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img   class=\"lazyload\" data-src=\"https:\/\/img-blog.csdnimg.cn\/20201213001236746.png\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/moezx\/cdn@3.0.2\/img\/svg\/loader\/trans.ajax-spinner-preloader.svg\" onerror=\"imgError(this)\"  alt=\"[\u5916\u94fe\u56fe\u7247\u8f6c\u5b58\u4e2d\u2026(img-eCm0qnl5-1607789521389)]\"\/><\/figure >\n<noscript><img src=\"https:\/\/img-blog.csdnimg.cn\/20201213001236746.png\" alt=\"[\u5916\u94fe\u56fe\u7247\u8f6c\u5b58\u4e2d\u2026(img-eCm0qnl5-1607789521389)]\"\/><\/figure><\/noscript>\n\n\n\n<pre class=\"wp-block-code\"><code>md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503c:071263445647839a7bc0de0ff0ed0cb0a908706504302100\nmd5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503c:021253435637849a1bc6de1ff8ed9cb0a908706504302100\n\u4e24\u6b21\u751f\u6210\u7684\u52a0\u76d0\u5bc6\u6587\u4e0d\u76f8\u7b49\uff01\n\u539f\u6765\u7684\u660e\u6587\u548c\u52a0\u76d0\u540e\u7684\u660e\u6587\u4e00\u81f4\u5f97\u5230\u9a8c\u8bc1!<\/code><\/pre>\n\n\n\n<p><strong>\u7531\u7ed3\u679c\u77e5\u9053\uff0c\u867d\u7136\u52a0\u76d0\u540e\u5f97\u5230\u7684\u5bc6\u6587\u4e0d\u4e00\u6837\uff0c\u4f46\u662f\u76f8\u540c\u7684\u660e\u6587\u4ea7\u751f\u7684\u5bc6\u6587\u662f\u53ef\u4ee5\u901a\u8fc7\u9a8c\u8bc1\u77e5\u9053\u539f\u6765\u7684\u660e\u6587\u662f\u5426\u4e00\u81f4\u7684\u3002<\/strong><\/p>\n\n\n\n<h2>7.\u5b8c\u6574\u7684\u4ee3\u7801<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#pragma once\n#include&lt;iostream>\n#include&lt;string>\n#include\"Md5.h\"\n#include&lt;time.h>\nusing namespace std;\n\nclass EncryptUtil\n{\npublic:\n    EncryptUtil();\n\/**\n*@param text:\u9700\u8981\u8fdb\u884c\u666e\u901amd5\u6458\u8981\u7b97\u6cd5\u8ba1\u7b97\u7684\u660e\u6587\n*@return string\uff1a\u8fd4\u56de\u666e\u901amd5\u6458\u8981\u7b97\u8ba1\u7b97\u540e\u7684\u5b57\u7b26\u4e32\n*\/\n    string md5Decode(const string&amp; text);\n\/**\n\u4ea7\u751f\u76d0\u503c\u5b57\u7b26\u4e32salt\n*\/\n    string createSalt();\n\n\/**\n* \u52a0\u76d0MD5\n* @param text : \u9700\u8981\u8fdb\u884c\u52a0\u76d0\u540e\u6458\u8981\u7684text\u660e\u6587\n* @return string\uff1a\u8fd4\u56de\u8fdb\u884c\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5b57\u7b26\u4e32\n*\/\n    string encryptBySalt(const string&amp; text);\n\/**\n * \u83b7\u53d6\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684MD5\u6458\u8981\n * @param text: \u9700\u8981\u8fdb\u884c\u6458\u8981\u7b97\u6cd5\u7684\u660e\u6587\n * @return string: \u8fd4\u56de\u8fdb\u884c\u666e\u901amd5\u6458\u8981\u540e\u7684\u5b57\u7b26\u4e32\n *\/\n    string md5Hex(const string&amp; src);\n\/**\n * \u6821\u9a8c\u52a0\u76d0\u540e\u662f\u5426\u548c\u539f\u6587\u4e00\u81f4\n * @param text : \u8fdb\u884c\u6458\u8981\u7b97\u6cd5\u7684\u660e\u6587\n * @param encryptText  \uff1a \u8fdb\u884c\u52a0\u76d0\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5bc6\u6587\n * @return \u5982\u679c\u52a0\u76d0\u540e\u548c\u539f\u660e\u6587text\u4e00\u81f4\u5219\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\n *\/\n    bool verify( string text,  string md5Text);\n\/**\n  \u9010\u4e2a\u6bd4\u8f83\u4e24\u4e2a\u5bc6\u6587\u76f8\u540c\u4f4d\u7f6e\u4e0a\u5b57\u7b26\u662f\u5426\u76f8\u540c\u6765\u8ba1\u7b97\u4e24\u4e2a\u8fdb\u884cmd5\u52a0\u5bc6\u540e\u7684\u76f8\u4f3c\u5ea6\u3002\n @param str1: md5\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5b57\u7b26\u4e32\n @param str2:md5\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5b57\u7b26\u4e32\n @return double: \u8fd4\u56de\u76f8\u4f3c\u5ea6\n *\/\n    double similarityDegree(const string&amp; str1, const string&amp; str2);\n    ~EncryptUtil();\nprivate:\n    MD5* md5 = nullptr;\n\n};<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"EncryptUtil.h\"\n\n\n\nEncryptUtil::EncryptUtil()\n{\n    \/\/\u521d\u59cb\u5316MD5\u8fd9\u4e2a\u7c7b\n    this->md5 = new MD5();\n    \/\/\u8bbe\u7f6e\u968f\u673a\u6570\u79cd\u5b50\uff0c\u5728\u4ea7\u751f\u76d0\u65f6\u53ef\u4ee5\u4ea7\u751f\u968f\u673a\u6570\u3002\n    srand(time(NULL));\n}\n\n\/**\n*@param text:\u9700\u8981\u8fdb\u884c\u666e\u901amd5\u6458\u8981\u7b97\u6cd5\u8ba1\u7b97\u7684\u660e\u6587\n*@return string\uff1a\u8fd4\u56de\u666e\u901amd5\u6458\u8981\u7b97\u8ba1\u7b97\u540e\u7684\u5b57\u7b26\u4e32\n*\/\nstring EncryptUtil::md5Decode(const string &amp; text)\n{\n    \/\/\u8c03\u7528md5Hex(text)\u51fd\u6570\u5373\u53ef\n     return this->md5Hex(text);\n}\n\/**\n\u4ea7\u751f\u76d0\u503c\u5b57\u7b26\u4e32salt\n*\/\nstring EncryptUtil::createSalt()\n{\n    \/\/\u968f\u673a\u751f\u6210\u4e24\u4e2a\u968f\u673a\u6570\n    int num1 = rand() % 99999999;\n    int num2 = rand() % 99999999;\n    string salt = \"\";\n    \/\/\u5c06\u8fd9\u4e24\u4e2a\u968f\u673a\u6570\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u540e\u8ffd\u52a0\u5230salt\u4e2d\n    salt.append(to_string(num1));\n    salt.append(to_string(num2));\n    \/\/salt\u4e0d\u591f\u5341\u516d\u4f4d\u5c31\u5728\u540e\u9762\u52a00\n    int len = salt.size();\n    if (len &lt; 16) {\n        for (int i = 0; i &lt; 16 - len; i++) {\n            salt.append(\"0\");\n        }\n    }\n    \/\/cout &lt;&lt; \"\u4ea7\u751f\u7684\u76d0\u503c\u5b57\u7b26\u4e32\u4e3a\uff1a\" &lt;&lt;salt&lt;&lt; endl;\n    return salt;\n}\n\n\/**\n* \u52a0\u76d0MD5\n* @param text : \u9700\u8981\u8fdb\u884c\u52a0\u76d0\u540e\u6458\u8981\u7684text\u660e\u6587\n* @return string\uff1a\u8fd4\u56de\u8fdb\u884c\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5b57\u7b26\u4e32\n*\/\nstring EncryptUtil::encryptBySalt(const string&amp; text) {\n    \/\/\u4ea7\u751f\u76d0\u503c\u5b57\u7b26\u4e32salt\n    string salt = createSalt();\n    \/\/\u5c06\u4ea7\u751f\u7684salt\u8ffd\u52a0\u5230\u9700\u8981\u8fdb\u884c\u6458\u8981\u7684\u660e\u6587text\u4e2d\uff0c\u5f97\u5230\u7531\u660e\u6587text\u548csalt\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\n    string merge_str =  text + salt;\n    \/\/\u4f7f\u7528md5\u7b97\u6cd5\u8fdb\u884c\u6458\u8981\u8ba1\u7b97\u5f97\u5230\u76f8\u5e94\u768432\u4f4d\u7684\u5bc6\u6587\n    string encodeText = md5Hex(merge_str);\n    char cs &#91;48];\n    \/\/\u5c0632\u4f4d\u7684\u5bc6\u6587\u548c\u4ea7\u751f\u768416\u4f4d\u7684salt\u8fdb\u884c\u91cd\u7ec4\u5f62\u6210\u65b0\u768448\u4f4d\u7684\u5b57\u7b26\u4e32\u3002\n    \/\/\u8fd9\u91cc\u8868\u793a\uff0c\u5728\u65b0\u7684\u5b57\u7b26\u6570\u7ec4cs\u4e2d\uff0csalt\u4e2d\u7684\u5b57\u7b26\u6dfb\u52a0\u5230cs\u5b57\u7b26\u6570\u7ec4\u4e2d\u4f4d\u7f6e\u662fi*3+1\u7684\u4f4d\u7f6e\uff0c\u5176\u5b83\u4f4d\u7f6e\u7531\u6458\u8981\u5bc6\u6587encodeText\u4e2d\u7684\u5b57\u7b26\u586b\u5145\n    for (int i = 0; i &lt; 48; i += 3) {\n        cs&#91;i] = encodeText&#91;i \/ 3 * 2];\n        char c = salt&#91;i \/ 3];\n        cs&#91;i + 1] = c;\n        cs&#91;i + 2] = encodeText&#91;i \/ 3 * 2 + 1];\n    }\n    \/\/\u5c06\u7ec4\u5408\u6210\u7684cs\u5b57\u7b26\u6570\u7ec4\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u5f97\u523048\u4f4d\u7684\u52a0\u76d0\u540e\u5f62\u6210\u7684md5\u6458\u8981\u5bc6\u6587\n    string code = \"\";\n    for (int i = 0; i &lt; 48; i++)\n    {\n      code.append(1,cs&#91;i]);\n    }\n    return code;\n}\n\/**\n * \u83b7\u53d6\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684MD5\u6458\u8981\n * @param text: \u9700\u8981\u8fdb\u884c\u6458\u8981\u7b97\u6cd5\u7684\u660e\u6587\n * @return string: \u8fd4\u56de\u8fdb\u884c\u666e\u901amd5\u6458\u8981\u540e\u7684\u5b57\u7b26\u4e32\n *\/\nstring EncryptUtil::md5Hex(const string&amp; text) {\n    \/\/\u9996\u5148\u66f4\u65b0md5\u4e2d\u9700\u8981\u8fdb\u884c\u6458\u8981\u7684\u5b57\u7b26\u4e32\n    this->md5->update(text);\n    \/\/\u4f7f\u7528md5\u7684\u65b9\u6cd5\u751f\u6210\u5bf9\u5e94\u7684\u6458\u8981\u540e\u7684\u5b57\u7b26\u4e32\n    return this->md5->toString();\n\n}\n\/**\n * \u6821\u9a8c\u52a0\u76d0\u540e\u662f\u5426\u548c\u539f\u6587\u4e00\u81f4\n * @param text : \u8fdb\u884c\u6458\u8981\u7b97\u6cd5\u7684\u660e\u6587\n * @param encryptText  \uff1a \u8fdb\u884c\u52a0\u76d0\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5bc6\u6587\n * @return \u5982\u679c\u52a0\u76d0\u540e\u548c\u539f\u660e\u6587text\u4e00\u81f4\u5219\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse\n *\/\n bool EncryptUtil::verify( string text,  string encryptText) {\n    char md5Text&#91;32];\n    char salt&#91;16];\n    \/\/\u9996\u5148\u5c06\u52a0\u76d0\u540emd5\u7b97\u6cd5\u6458\u8981\u5f97\u5230\u7684encryptText\u5bc6\u6587\u8fdb\u884c\u62c6\u5206\u6210\u4e00\u4e2a32\u4f4d\u7684\u666e\u901amd5\u6458\u8981\u7b97\u6cd5\u5bc6\u6587md5Text\u548c\u4e00\u4e2a16\u4f4d\u7684\u5b57\u7b26\u4e32salt\u3002\n    \/\/\u8fd9\u91cc\u5c31\u662f\u8fdb\u884csalt\u548cmd5\u6458\u8981\u5bc6\u6587\u5f62\u621048\u4f4d\u65b0\u7684\u5b57\u7b26\u4e32encryptText\u65f6\u7684\u9006\u5411\u64cd\u4f5c\u3002encryptText\u4e2dsalt&#91;i] =  encryptText&#91; 3* i + 1], i = 0,1,2,...16\n    for (int i = 0; i &lt; 48; i += 3) {\n        md5Text&#91;i \/ 3 * 2] = encryptText&#91;i];\n        md5Text&#91;i \/ 3 * 2 + 1] = encryptText&#91;i + 2];\n        salt&#91;i \/ 3] = encryptText&#91;i + 1];\n    }\n    \/\/\u5c06\u62c6\u5206\u768416\u4e2a\u968f\u673a\u5b57\u7b26\u4e32\u8ffdsalt\u52a0\u5230\u660e\u6587text\u4e2d\n    for (int  i = 0; i &lt; 16; i++)\n    {\n        text.append(1,salt&#91;i]);\n    }\n    \/\/\u4f7f\u7528md5\u6458\u8981\u7b97\u6cd5\u8fdb\u884c\u751f\u6210\u5bc6\u6587\u5f97\u5230enCs2\n    string enCs2 = md5Hex(text);\n    \/\/\u6bd4\u8f83\u4e24\u4e2a\u5b57\u7b26\u4e32\u76f8\u7b49\uff0c\u5982\u679c\u76f8\u7b49\u5219\u8fd4\u56detrue\uff0c\u53ea\u8981\u6709\u4e00\u4e2a\u5b57\u7b26\u4e0d\u76f8\u7b49\u5c31\u8fd4\u56defalse\n    for (int i = 0; i &lt; enCs2.size(); i++)\n    {\n        if (enCs2&#91;i] != md5Text&#91;i])\n        {\n            return false;\n        }\n    }\n    return true;\n}\n \/**\n  \u9010\u4e2a\u6bd4\u8f83\u4e24\u4e2a\u5bc6\u6587\u76f8\u540c\u4f4d\u7f6e\u4e0a\u5b57\u7b26\u662f\u5426\u76f8\u540c\u6765\u8ba1\u7b97\u4e24\u4e2a\u660e\u6587\u8fdb\u884cmd5\u52a0\u5bc6\u540e\u7684\u76f8\u4f3c\u5ea6\u3002\n @param str1: md5\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5b57\u7b26\u4e32\n @param str2:md5\u6458\u8981\u7b97\u6cd5\u540e\u7684\u5b57\u7b26\u4e32\n @return double: \u8fd4\u56de\u76f8\u4f3c\u5ea6\n *\/\ndouble EncryptUtil::similarityDegree(const string&amp; str1, const string&amp; str2)\n{\n    if (str1.size() &lt;= 0 &amp;&amp; (str1.size() != str2.size()))\n    {\n        return 0;\n    }\n    int count = 0;\n    \/\/\u7edf\u8ba1\u5bf9\u5e94\u4f4d\u7f6e\u4e0a\u5b57\u7b26\u76f8\u540c\u7684\u4e2a\u6570\n    for (int i = 0; i &lt; str1.size(); i++)\n    {\n        if (str1&#91;i] == str2&#91;i])\n        {\n            count++;\n        }\n    }\n    \/\/\u8ba1\u7b97\u76f8\u4f3c\u5ea6\n    double result = count * 1.0 \/ str1.size();\n    return result;\n}\n\n\n\nEncryptUtil::~EncryptUtil()\n{\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#pragma once\n#ifndef MD5_H\n#define MD5_H\n#include &lt;string>\n#include &lt;fstream>\nusing namespace std;\n\/* Type define *\/\ntypedef unsigned char byte;\ntypedef unsigned int uint32;\n\n\n\n\/* MD5 declaration. *\/\nclass MD5 {\npublic:\n    MD5();\n    MD5(const void *input, size_t length);\n    MD5(const string &amp;str);\n    MD5(ifstream &amp;in);\n    void update(const void *input, size_t length);\n    void update(const string &amp;str);\n    void update(ifstream &amp;in);\n    const byte* digest();\n    string toString();\n\nprivate:\n    void reset();\n    void update(const byte *input, size_t length);\n    void final();\n    void transform(const byte block&#91;64]);\n    void encode(const uint32 *input, byte *output, size_t length);\n    void decode(const byte *input, uint32 *output, size_t length);\n    string bytesToHexString(const byte *input, size_t length);\n    \/* class uncopyable *\/\n    MD5(const MD5&amp;);\n    MD5&amp; operator=(const MD5&amp;);\nprivate:\n    uint32 _state&#91;4];   \/* state (ABCD) *\/\n    uint32 _count&#91;2];   \/* number of bits, modulo 2^64 (low-order word first) *\/\n    byte _buffer&#91;64];   \/* input buffer *\/\n    byte _digest&#91;16];   \/* message digest *\/\n    bool _finished;     \/* calculate finished ? *\/\n    static const byte PADDING&#91;64];  \/* padding for calculate *\/\n    static const char HEX&#91;16];\n    static const size_t BUFFER_SIZE = 1024;\n};\n\n#endif\/*MD5_H*\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"md5.h\"\n\n\n\n\/* Constants for MD5Transform routine. *\/\n#define S11 7\n#define S12 12\n#define S13 17\n#define S14 22\n#define S21 5\n#define S22 9\n#define S23 14\n#define S24 20\n#define S31 4\n#define S32 11\n#define S33 16\n#define S34 23\n#define S41 6\n#define S42 10\n#define S43 15\n#define S44 21\n\n\n\/* F, G, H and I are basic MD5 functions.\n*\/\n#define F(x, y, z) (((x) &amp; (y)) | ((~x) &amp; (z)))\n#define G(x, y, z) (((x) &amp; (z)) | ((y) &amp; (~z)))\n#define H(x, y, z) ((x) ^ (y) ^ (z))\n#define I(x, y, z) ((y) ^ ((x) | (~z)))\n\n\/* ROTATE_LEFT rotates x left n bits.\n*\/\n#define ROTATE_LEFT(x, n) (((x) &lt;&lt; (n)) | ((x) >> (32-(n))))\n\n\/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.\nRotation is separate from addition to prevent recomputation.\n*\/\n#define FF(a, b, c, d, x, s, ac) { \\\n    (a) += F ((b), (c), (d)) + (x) + ac; \\\n    (a) = ROTATE_LEFT ((a), (s)); \\\n    (a) += (b); \\\n}\n#define GG(a, b, c, d, x, s, ac) { \\\n    (a) += G ((b), (c), (d)) + (x) + ac; \\\n    (a) = ROTATE_LEFT ((a), (s)); \\\n    (a) += (b); \\\n}\n#define HH(a, b, c, d, x, s, ac) { \\\n    (a) += H ((b), (c), (d)) + (x) + ac; \\\n    (a) = ROTATE_LEFT ((a), (s)); \\\n    (a) += (b); \\\n}\n#define II(a, b, c, d, x, s, ac) { \\\n    (a) += I ((b), (c), (d)) + (x) + ac; \\\n    (a) = ROTATE_LEFT ((a), (s)); \\\n    (a) += (b); \\\n}\nconst byte MD5::PADDING&#91;64] = { 0x80 };\nconst char MD5::HEX&#91;16] = {\n    '0', '1', '2', '3',\n    '4', '5', '6', '7',\n    '8', '9', 'a', 'b',\n    'c', 'd', 'e', 'f'\n};\n\n\/* Default construct. *\/\nMD5::MD5() {\n    reset();\n}\n\n\/* Construct a MD5 object with a input buffer. *\/\nMD5::MD5(const void *input, size_t length) {\n    reset();\n    update(input, length);\n}\n\n\/* Construct a MD5 object with a string. *\/\nMD5::MD5(const string &amp;str) {\n    reset();\n    update(str);\n}\n\n\/* Construct a MD5 object with a file. *\/\nMD5::MD5(ifstream &amp;in) {\n    reset();\n    update(in);\n}\n\n\/* Return the message-digest *\/\nconst byte* MD5::digest() {\n    if (!_finished) {\n        _finished = true;\n        final();\n    }\n    return _digest;\n}\n\n\/* Reset the calculate state *\/\nvoid MD5::reset() {\n\n    _finished = false;\n    \/* reset number of bits. *\/\n    _count&#91;0] = _count&#91;1] = 0;\n    \/* Load magic initialization constants. *\/\n    _state&#91;0] = 0x67452301;\n    _state&#91;1] = 0xefcdab89;\n    _state&#91;2] = 0x98badcfe;\n    _state&#91;3] = 0x10325476;\n\n}\n\n\/* Updating the context with a input buffer. *\/\nvoid MD5::update(const void *input, size_t length) {\n    update((const byte*)input, length);\n}\n\n\/* Updating the context with a string. *\/\nvoid MD5::update(const string &amp;str) {\n    update((const byte*)str.c_str(), str.length());\n}\n\n\/* Updating the context with a file. *\/\nvoid MD5::update(ifstream &amp;in) {\n\n    if (!in)\n        return;\n\n    std::streamsize length;\n    char buffer&#91;BUFFER_SIZE];\n    while (!in.eof()) {\n        in.read(buffer, BUFFER_SIZE);\n        length = in.gcount();\n        if (length > 0)\n            update(buffer, length);\n    }\n    in.close();\n}\n\n\/* MD5 block update operation. Continues an MD5 message-digest\noperation, processing another message block, and updating the\ncontext.\n*\/\nvoid MD5::update(const byte *input, size_t length) {\n\n    uint32 i, index, partLen;\n\n    \/\/_finished = false;\n    this->reset();\n    \/* Compute number of bytes mod 64 *\/\n    index = (uint32)((_count&#91;0] >> 3) &amp; 0x3f);\n\n    \/* update number of bits *\/\n    if ((_count&#91;0] += ((uint32)length &lt;&lt; 3)) &lt; ((uint32)length &lt;&lt; 3))\n        _count&#91;1]++;\n    _count&#91;1] += ((uint32)length >> 29);\n\n    partLen = 64 - index;\n\n    \/* transform as many times as possible. *\/\n    if (length >= partLen) {\n\n        memcpy(&amp;_buffer&#91;index], input, partLen);\n        transform(_buffer);\n\n        for (i = partLen; i + 63 &lt; length; i += 64)\n            transform(&amp;input&#91;i]);\n        index = 0;\n\n    }\n    else {\n        i = 0;\n    }\n\n    \/* Buffer remaining input *\/\n    memcpy(&amp;_buffer&#91;index], &amp;input&#91;i], length - i);\n}\n\n\/* MD5 finalization. Ends an MD5 message-_digest operation, writing the\nthe message _digest and zeroizing the context.\n*\/\nvoid MD5::final() {\n\n    byte bits&#91;8];\n    uint32 oldState&#91;4];\n    uint32 oldCount&#91;2];\n    uint32 index, padLen;\n\n    \/* Save current state and count. *\/\n    memcpy(oldState, _state, 16);\n    memcpy(oldCount, _count, 8);\n\n    \/* Save number of bits *\/\n    encode(_count, bits, 8);\n\n    \/* Pad out to 56 mod 64. *\/\n    index = (uint32)((_count&#91;0] >> 3) &amp; 0x3f);\n    padLen = (index &lt; 56) ? (56 - index) : (120 - index);\n    update(PADDING, padLen);\n\n    \/* Append length (before padding) *\/\n    update(bits, 8);\n\n    \/* Store state in digest *\/\n    encode(_state, _digest, 16);\n\n    \/* Restore current state and count. *\/\n    memcpy(_state, oldState, 16);\n    memcpy(_count, oldCount, 8);\n}\n\n\/* MD5 basic transformation. Transforms _state based on block. *\/\nvoid MD5::transform(const byte block&#91;64]) {\n\n    uint32 a = _state&#91;0], b = _state&#91;1], c = _state&#91;2], d = _state&#91;3], x&#91;16];\n\n    decode(block, x, 64);\n\n    \/* Round 1 *\/\n    FF(a, b, c, d, x&#91;0], S11, 0xd76aa478); \/* 1 *\/\n    FF(d, a, b, c, x&#91;1], S12, 0xe8c7b756); \/* 2 *\/\n    FF(c, d, a, b, x&#91;2], S13, 0x242070db); \/* 3 *\/\n    FF(b, c, d, a, x&#91;3], S14, 0xc1bdceee); \/* 4 *\/\n    FF(a, b, c, d, x&#91;4], S11, 0xf57c0faf); \/* 5 *\/\n    FF(d, a, b, c, x&#91;5], S12, 0x4787c62a); \/* 6 *\/\n    FF(c, d, a, b, x&#91;6], S13, 0xa8304613); \/* 7 *\/\n    FF(b, c, d, a, x&#91;7], S14, 0xfd469501); \/* 8 *\/\n    FF(a, b, c, d, x&#91;8], S11, 0x698098d8); \/* 9 *\/\n    FF(d, a, b, c, x&#91;9], S12, 0x8b44f7af); \/* 10 *\/\n    FF(c, d, a, b, x&#91;10], S13, 0xffff5bb1); \/* 11 *\/\n    FF(b, c, d, a, x&#91;11], S14, 0x895cd7be); \/* 12 *\/\n    FF(a, b, c, d, x&#91;12], S11, 0x6b901122); \/* 13 *\/\n    FF(d, a, b, c, x&#91;13], S12, 0xfd987193); \/* 14 *\/\n    FF(c, d, a, b, x&#91;14], S13, 0xa679438e); \/* 15 *\/\n    FF(b, c, d, a, x&#91;15], S14, 0x49b40821); \/* 16 *\/\n\n    \/* Round 2 *\/\n    GG(a, b, c, d, x&#91;1], S21, 0xf61e2562); \/* 17 *\/\n    GG(d, a, b, c, x&#91;6], S22, 0xc040b340); \/* 18 *\/\n    GG(c, d, a, b, x&#91;11], S23, 0x265e5a51); \/* 19 *\/\n    GG(b, c, d, a, x&#91;0], S24, 0xe9b6c7aa); \/* 20 *\/\n    GG(a, b, c, d, x&#91;5], S21, 0xd62f105d); \/* 21 *\/\n    GG(d, a, b, c, x&#91;10], S22, 0x2441453); \/* 22 *\/\n    GG(c, d, a, b, x&#91;15], S23, 0xd8a1e681); \/* 23 *\/\n    GG(b, c, d, a, x&#91;4], S24, 0xe7d3fbc8); \/* 24 *\/\n    GG(a, b, c, d, x&#91;9], S21, 0x21e1cde6); \/* 25 *\/\n    GG(d, a, b, c, x&#91;14], S22, 0xc33707d6); \/* 26 *\/\n    GG(c, d, a, b, x&#91;3], S23, 0xf4d50d87); \/* 27 *\/\n    GG(b, c, d, a, x&#91;8], S24, 0x455a14ed); \/* 28 *\/\n    GG(a, b, c, d, x&#91;13], S21, 0xa9e3e905); \/* 29 *\/\n    GG(d, a, b, c, x&#91;2], S22, 0xfcefa3f8); \/* 30 *\/\n    GG(c, d, a, b, x&#91;7], S23, 0x676f02d9); \/* 31 *\/\n    GG(b, c, d, a, x&#91;12], S24, 0x8d2a4c8a); \/* 32 *\/\n\n    \/* Round 3 *\/\n    HH(a, b, c, d, x&#91;5], S31, 0xfffa3942); \/* 33 *\/\n    HH(d, a, b, c, x&#91;8], S32, 0x8771f681); \/* 34 *\/\n    HH(c, d, a, b, x&#91;11], S33, 0x6d9d6122); \/* 35 *\/\n    HH(b, c, d, a, x&#91;14], S34, 0xfde5380c); \/* 36 *\/\n    HH(a, b, c, d, x&#91;1], S31, 0xa4beea44); \/* 37 *\/\n    HH(d, a, b, c, x&#91;4], S32, 0x4bdecfa9); \/* 38 *\/\n    HH(c, d, a, b, x&#91;7], S33, 0xf6bb4b60); \/* 39 *\/\n    HH(b, c, d, a, x&#91;10], S34, 0xbebfbc70); \/* 40 *\/\n    HH(a, b, c, d, x&#91;13], S31, 0x289b7ec6); \/* 41 *\/\n    HH(d, a, b, c, x&#91;0], S32, 0xeaa127fa); \/* 42 *\/\n    HH(c, d, a, b, x&#91;3], S33, 0xd4ef3085); \/* 43 *\/\n    HH(b, c, d, a, x&#91;6], S34, 0x4881d05); \/* 44 *\/\n    HH(a, b, c, d, x&#91;9], S31, 0xd9d4d039); \/* 45 *\/\n    HH(d, a, b, c, x&#91;12], S32, 0xe6db99e5); \/* 46 *\/\n    HH(c, d, a, b, x&#91;15], S33, 0x1fa27cf8); \/* 47 *\/\n    HH(b, c, d, a, x&#91;2], S34, 0xc4ac5665); \/* 48 *\/\n\n    \/* Round 4 *\/\n    II(a, b, c, d, x&#91;0], S41, 0xf4292244); \/* 49 *\/\n    II(d, a, b, c, x&#91;7], S42, 0x432aff97); \/* 50 *\/\n    II(c, d, a, b, x&#91;14], S43, 0xab9423a7); \/* 51 *\/\n    II(b, c, d, a, x&#91;5], S44, 0xfc93a039); \/* 52 *\/\n    II(a, b, c, d, x&#91;12], S41, 0x655b59c3); \/* 53 *\/\n    II(d, a, b, c, x&#91;3], S42, 0x8f0ccc92); \/* 54 *\/\n    II(c, d, a, b, x&#91;10], S43, 0xffeff47d); \/* 55 *\/\n    II(b, c, d, a, x&#91;1], S44, 0x85845dd1); \/* 56 *\/\n    II(a, b, c, d, x&#91;8], S41, 0x6fa87e4f); \/* 57 *\/\n    II(d, a, b, c, x&#91;15], S42, 0xfe2ce6e0); \/* 58 *\/\n    II(c, d, a, b, x&#91;6], S43, 0xa3014314); \/* 59 *\/\n    II(b, c, d, a, x&#91;13], S44, 0x4e0811a1); \/* 60 *\/\n    II(a, b, c, d, x&#91;4], S41, 0xf7537e82); \/* 61 *\/\n    II(d, a, b, c, x&#91;11], S42, 0xbd3af235); \/* 62 *\/\n    II(c, d, a, b, x&#91;2], S43, 0x2ad7d2bb); \/* 63 *\/\n    II(b, c, d, a, x&#91;9], S44, 0xeb86d391); \/* 64 *\/\n\n    _state&#91;0] += a;\n    _state&#91;1] += b;\n    _state&#91;2] += c;\n    _state&#91;3] += d;\n}\n\n\/* Encodes input (ulong) into output (byte). Assumes length is\na multiple of 4.\n*\/\nvoid MD5::encode(const uint32 *input, byte *output, size_t length) {\n\n    for (size_t i = 0, j = 0; j &lt; length; i++, j += 4) {\n        output&#91;j] = (byte)(input&#91;i] &amp; 0xff);\n        output&#91;j + 1] = (byte)((input&#91;i] >> 8) &amp; 0xff);\n        output&#91;j + 2] = (byte)((input&#91;i] >> 16) &amp; 0xff);\n        output&#91;j + 3] = (byte)((input&#91;i] >> 24) &amp; 0xff);\n    }\n}\n\n\/* Decodes input (byte) into output (ulong). Assumes length is\na multiple of 4.\n*\/\nvoid MD5::decode(const byte *input, uint32 *output, size_t length) {\n\n    for (size_t i = 0, j = 0; j &lt; length; i++, j += 4) {\n        output&#91;i] = ((uint32)input&#91;j]) | (((uint32)input&#91;j + 1]) &lt;&lt; 8) |\n            (((uint32)input&#91;j + 2]) &lt;&lt; 16) | (((uint32)input&#91;j + 3]) &lt;&lt; 24);\n    }\n}\n\n\/* Convert byte array to hex string. *\/\nstring MD5::bytesToHexString(const byte *input, size_t length) {\n    string str;\n    str.reserve(length &lt;&lt; 1);\n    for (size_t i = 0; i &lt; length; i++) {\n        int t = input&#91;i];\n        int a = t \/ 16;\n        int b = t % 16;\n        str.append(1, HEX&#91;a]);\n        str.append(1, HEX&#91;b]);\n    }\n    return str;\n}\n\nMD5 &amp; MD5::operator=(const MD5 &amp;)\n{\n    return *this;\n}\n\n\/* Convert digest to string value *\/\nstring MD5::toString() {\n    return bytesToHexString(digest(), 16);\n}<\/code><\/pre>\n\n\n\n<p><strong>\u6d4b\u8bd5\u6587\u4ef6<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include\"Md5.h\"\n#include&lt;string>\n#include&lt;fstream>\n#include\"EncryptUtil.h\"\n#include&lt;time.h>\n#include&lt;vector>\nusing namespace std;\n\nstring loadTextToString(const string textFilePath) {\n    ifstream* ism = new ifstream(textFilePath,ios::app|ios::binary);\n    if (ism->is_open())\n    {\n\n        string text = \"\";\n        char ch;\n        while (!ism->eof())\n        {\n            ism->get(ch);\n            text.append(1,ch);\n        }\n        return text;\n    }\n    else {\n        cout &lt;&lt; \"\u6253\u5f00\u6587\u4ef6\u5931\u8d25!\" &lt;&lt; endl;\n        return \"\";\n    }\n}\n\nvoid test2() {\n\n\n}\nvoid test1() {\n    string text = loadTextToString(\"hashtext.txt\");\n    MD5 md5(text);\n    cout &lt;&lt; md5.toString();\n}\nvoid test3() {\n    string s = \"11\";\n    s.append(to_string(121));\n    cout &lt;&lt; s;\n}\nvoid test4() {\n    string text = loadTextToString(\"hashtext.txt\");\n    EncryptUtil util;\n    string str = util.md5Decode(text);\n    cout &lt;&lt; \"\\n\u666e\u901a\u52a0\u5bc6\u540e\u7684md5\u503c\uff1a\" + str &lt;&lt; endl;\n    cout &lt;&lt; \"\u666e\u901a\u52a0\u5bc6\u540e\u7684md5\u503c\uff1a\" + util.md5Decode(text) &lt;&lt; endl;\n    string encodeText =util.encryptBySalt(text);\n    string encodeText1 = util.encryptBySalt(text);\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503c:\" + encodeText &lt;&lt; endl;\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503c:\" + encodeText1 &lt;&lt; endl;\n    if (encodeText.compare(encodeText1) == 0)\n    {\n        cout &lt;&lt; \"\u4e24\u6b21\u751f\u6210\u7684\u52a0\u76d0\u79d8\u94a5\u76f8\u7b49\uff01\" &lt;&lt; endl;\n    }\n    else {\n        cout &lt;&lt; \"\u4e24\u6b21\u751f\u6210\u7684\u52a0\u76d0\u79d8\u94a5\u4e0d\u76f8\u7b49\uff01\" &lt;&lt; endl;\n    }\n    bool fla = util.verify(text,encodeText);\n    if (fla == true)\n    {\n        cout &lt;&lt; \"\u76f8\u7b49!\"&lt;&lt;endl;\n    }\n    else {\n        cout &lt;&lt; \"\u4e0d\u76f8\u7b49\" &lt;&lt; endl;\n    }\n\n}\nvoid test5() {\n    string text = loadTextToString(\"hashtext.txt\");\n    cout &lt;&lt; endl;\n\n}\nvoid test6() {\n    srand(time(NULL));\n    cout &lt;&lt; rand() % 99999999 &lt;&lt;\"  \"&lt;&lt;  rand()% 99999999 &lt;&lt;endl;\n    cout &lt;&lt; rand() % 99999999 &lt;&lt; \"  \" &lt;&lt; rand() % 99999999 &lt;&lt; endl;\n}\nvoid test7() {\n    string text = loadTextToString(\"hashtext.txt\");\n    cout &lt;&lt; \"\u9700\u8981\u52a0\u5bc6\u7684\u660e\u6587\u4e3a\uff1a\\n\" &lt;&lt; text&lt;&lt;endl;\n    EncryptUtil util;\n    string encodeText = util.encryptBySalt(text);\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503c:\" + encodeText &lt;&lt; endl;\n\n\n}\nstring randomReplace(string text,int index,string replaceChar) {\n\n\n\n    return text.replace(index,1,replaceChar);\n}\nvoid test() {\n    string text = loadTextToString(\"hashtext.txt\");\n    cout &lt;&lt; \"\u9700\u8981\u52a0\u5bc6\u7684\u660e\u6587\u4e3a\uff1a\\n\" &lt;&lt; text &lt;&lt; endl;\n    EncryptUtil util;\n    string md0 = util.encryptBySalt(text);\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH0:\" + md0 &lt;&lt; endl;\n    vector&lt;string> vec;\n    for (int i = 0; i &lt; 10; i++)\n    {\n        \/\/\u66ff\u6362\u5341\u4e2a\u5b57\u7b26\uff0c\u6bcf\u4e2a\u539f\u6765\u7684\u5b57\u7b26+1\n        string  newStr =    randomReplace(text, i * 5,string(1, text&#91;i * 5] + 1));\n        \/\/\u8ba1\u7b97\u6bcf\u4e2a\u66ff\u6362\u540e\u5b57\u7b26\u7684hash\u503c\n         string encodeText =util.encryptBySalt(newStr);\n        vec.push_back(encodeText);\n    }\n    for (size_t i = 0; i &lt; 10; i++)\n    {\n        cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH\"+ to_string(i + 1) + \":\" + vec&#91;i]&lt;&lt; endl;\n    }\n    for (size_t i = 0; i &lt; 10; i++)\n    {\n        \/\/\u8ba1\u7b97H0\u548cH\u7684\u76f8\u4f3c\u5ea6\n        cout &lt;&lt; \"H0\u548cH\" + to_string(i + 1) + \"\u7684\u76f8\u4f3c\u5ea6:\" + to_string(util.similarityDegree(md0, vec&#91;i])) &lt;&lt; endl;\n    }\n}\nvoid test8() {\n    string text = loadTextToString(\"hashtext.txt\");\n    cout &lt;&lt; \"\u9700\u8981\u52a0\u5bc6\u7684\u660e\u6587\u4e3a\uff1a\\n\" &lt;&lt; text &lt;&lt; endl;\n    EncryptUtil util;\n    string md0 = util.encryptBySalt(text);\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH0:\" + md0 &lt;&lt; endl;\n    string text1 =  text.replace(10,1,\"a\");\n    string md1 = util.encryptBySalt(text1);\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503cH1:\" + md1 &lt;&lt; endl;\n    cout &lt;&lt; \"md0\u548cmd1\u76f8\u4f3c\u5ea6\uff1a\" &lt;&lt; util.similarityDegree(md0,md1)&lt;&lt;endl;\n\n}\nvoid test9() {\n    string text = loadTextToString(\"hashtext.txt\");\n    EncryptUtil util;\n    string encodeText = util.encryptBySalt(text);\n    string encodeText1 = util.encryptBySalt(text);\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503c:\" + encodeText &lt;&lt; endl;\n    cout &lt;&lt; \"md5\u52a0\u76d0\u540e\u52a0\u5bc6\u7684md5\u503c:\" + encodeText1 &lt;&lt; endl;\n    if (encodeText.compare(encodeText1) == 0)\n    {\n        cout &lt;&lt; \"\u4e24\u6b21\u751f\u6210\u7684\u52a0\u76d0\u5bc6\u6587\u76f8\u7b49\uff01\" &lt;&lt; endl;\n    }\n    else {\n        cout &lt;&lt; \"\u4e24\u6b21\u751f\u6210\u7684\u52a0\u76d0\u5bc6\u6587\u4e0d\u76f8\u7b49\uff01\" &lt;&lt; endl;\n    }\n    bool fla = util.verify(text, encodeText);\n    if (fla == true)\n    {\n        cout &lt;&lt; \"\u539f\u6765\u7684\u660e\u6587\u548c\u52a0\u76d0\u540e\u7684\u660e\u6587\u4e00\u81f4\u5f97\u5230\u9a8c\u8bc1!\" &lt;&lt; endl;\n    }\n    else {\n        cout &lt;&lt; \"\u539f\u6765\u7684\u660e\u6587\u548c\u52a0\u76d0\u540e\u7684\u660e\u6587\u4e0d\u4e00\u81f4!\" &lt;&lt; endl;\n    }\n\n}\nint main() {\n    \/\/ test8();\n\n\n    test9();\n    system(\"pause\");\n    return 0;\n}<\/code><\/pre>\n\n\n\n<h2>8.\u770b\u5b8c\u8bb0\u5f97\u70b9\u8d5e\u54e6\uff0c\u7b14\u8bb0\u6574\u7406\u4e0d\u6613\u3002<\/h2>\n\n\n\n<h2><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>1.\u4fe1\u606f\u6458\u8981\u51fd\u6570(Hash\u51fd\u6570)\u7684\u8bbe\u8ba1\u4e0e\u6027\u8d28\u9a8c\u8bc1\u5b9e\u9a8c 2.\u5b9e\u9a8c\u76ee\u7684\uff1a\u4fe1\u606f\u6458\u8981\u51fd\u6570(Hash\u51fd\u6570)\u7684\u8bbe\u8ba1\u4e0e\u6027\u8d28\u9a8c\u8bc1\u3002 2.1\u5b9e\u9a8c\u8bbe\u5907 &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[163],"tags":[173,172,171,170,169,167],"_links":{"self":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/433"}],"collection":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":1,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":434,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/posts\/433\/revisions\/434"}],"wp:attachment":[{"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/moyisuiying.com\/index.php\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}