{"id":4182,"date":"2020-03-10T14:55:50","date_gmt":"2020-03-10T06:55:50","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=4182"},"modified":"2020-03-10T14:55:50","modified_gmt":"2020-03-10T06:55:50","slug":"blowfish-%e5%8a%a0%e5%af%86%e7%ae%97%e6%b3%95bcrypt","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/4182","title":{"rendered":"BlowFish \u52a0\u5bc6\u7b97\u6cd5Bcrypt\u00a0"},"content":{"rendered":"<div class=\"extra ui horizontal list meta-wrap\">\n<div class=\"item comment-count\"><a href=\"https:\/\/my.oschina.net\/u\/3664884\/blog\/1607425\">\u539f\u6587\u5730\u5740<\/a><\/div>\n<div><\/div>\n<\/div>\n<div id=\"articleContent\" class=\"content\">\n<blockquote><p>Blowfish\u662f1993\u5e74\u5e03\u9c81\u65af\u00b7\u65bd\u5948\u5c14(Bruce Schneier)\u5f00\u53d1\u7684\u5bf9\u79f0\u5bc6\u94a5\u533a\u5757\u52a0\u5bc6\u7b97\u6cd5\uff0c\u533a\u5757\u957f\u4e3a64\u4f4d\uff0c\u5bc6\u94a5\u4e3a1\u81f3448\u4f4d\u7684\u53ef\u53d8\u957f\u5ea6\u3002\u4e0eDES\u7b49\u7b97\u6cd5\u76f8\u6bd4\uff0c\u5176\u5904\u7406\u901f\u5ea6\u8f83\u5feb\u3002\u56e0\u4e3a\u5176\u65e0\u987b\u6388\u6743\u5373\u53ef\u4f7f\u7528\uff0c\u4f5c\u4e3a\u4e00\u79cd\u81ea\u7531\u6388\u6743\u7684\u52a0\u5bc6\u65b9\u5f0f\u5728SSH\u3001\u6587\u4ef6\u52a0\u5bc6\u8f6f\u4ef6\u7b49\u88ab\u5e7f\u6cdb\u5730\u4f7f\u7528\u3002<\/p><\/blockquote>\n<p>\u5173\u4e8e\u6b64\u7b97\u6cd5\u7684\u53d1\u660e\u8005\uff1a<\/p>\n<blockquote><p><a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fzh.wikipedia.org%2Fwiki%2FBruce_Schneier\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">\u5e03\u9c81\u65af\u00b7\u65bd\u5948\u5c14<\/a>\u00a0\uff08Bruce Schneier\uff0c1963\u5e741\u670815\u65e5\uff0d\uff09\u662f\u4e00\u4f4d\u7f8e\u56fd\u7684\u5bc6\u7801\u5b66\u5b66\u8005\u3001\u4fe1\u606f\u5b89\u5168\u4e13\u5bb6\u4e0e\u4f5c\u5bb6\u3002\u4ed6\u64b0\u5199\u4e86\u6570\u672c\u4fe1\u606f\u5b89\u5168\u4e0e\u5bc6\u7801\u5b66\u76f8\u5173\u7684\u4e66\u7c4d\uff0c\u5e76\u4e14\u521b\u529e\u4e86BT\u516c\u53f8\u5e76\u62c5\u4efb\u5176\u9996\u5e2d\u6280\u672f\u5b98(CTO)\u3002<\/p><\/blockquote>\n<p><span id=\"OSC_h3_1\"><\/span><\/p>\n<h3 id=\"h3_1\">\u5206\u7ec4\u5bc6\u7801(Block cypher)<\/h3>\n<p>\u5206\u7ec4\u5bc6\u7801\uff08Block cypher\uff0c\u53c8\u79f0<a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fzh.wikipedia.org%2Fwiki%2F%25E5%25A1%258A%25E5%25AF%2586%25E7%25A2%25BC\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">\u5206\u5757\u5bc6\u7801<\/a>\uff09\uff0c\u662f\u4e00\u79cd\u5bf9\u79f0\u5bc6\u94a5\u5bc6\u7801\u3002\u5b83\u7684\u7279\u70b9\u662f\u5c06\u660e\u6587\u5206\u6210\u591a\u4e2a\u7b49\u957f\u7684\u7ec4\uff0c\u5e76\u7528\u76f8\u540c\u7684\u5bc6\u7801\u7b97\u6cd5\u548c\u5bc6\u94a5\u5bf9\u6bcf\u7ec4\u5206\u522b\u8fdb\u884c\u52a0\u5bc6\u548c\u89e3\u5bc6\u3002\u5176\u4e2d\u5178\u578b\u7684\u5982DES\u548cAES\u4f5c\u4e3a\u7f8e\u56fd\u653f\u5e9c\u6838\u5b9a\u7684\u6807\u51c6\u52a0\u5bc6\u7b97\u6cd5\uff0c\u5e94\u7528\u9886\u57df\u4ece\u7535\u5b50\u90ae\u4ef6\u52a0\u5bc6\u5230\u94f6\u884c\u4ea4\u6613\u8f6c\u5e10\uff0c\u975e\u5e38\u5e7f\u6cdb\u3002<br \/>\nblowfish\u5c5e\u4e8e\u5206\u7ec4\u5bc6\u7801\u4e2d\u7684\u4e00\u79cd\u3002<\/p>\n<p>\u8981\u4e86\u89e3blowfish\u52a0\u5bc6\u7b97\u6cd5\uff0c\u4e5f\u8bb8\u6211\u4eec\u5e94\u8be5\u5148\u4e86\u89e3\u4e00\u4e0b<a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FFeistel_cipher\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Feistel \u5bc6\u7801<\/a>,\u56e0\u4e3ablowfish\u52a0\u5bc6\u7b97\u6cd5\u4e5f\u662ffeistel\u5bc6\u7801\u7b97\u6cd5\u4e2d\u7684\u4e00\u79cd\uff1a<br \/>\n\u5047\u8bbeF\u662f\u8f6e\u51fd\u6570\uff0c\u7136\u540eK0\u5230Kn\u4f5c\u4e3a0\u5230n\u8f6e\u7684sub-keys,<br \/>\n\u57fa\u672c\u7684\u64cd\u4f5c\u5982\u4e0b\uff1a<\/p>\n<p>\u628a\u660e\u6587\u5206\u4e3a\u76f8\u7b49\u7684\u4e24\u5757\uff1aL0\u548cR0,<br \/>\n\u5bf9\u4e8e\u6bcf\u4e00\u8f6ei=0,1,2,\u2026,n \u8fdb\u884c\u5982\u4e0b\u8fd0\u7b97\uff1a<br \/>\nLi+1 = Ri<br \/>\nRi+1 = Li ^ F(Ri,Ki)<br \/>\n\u6700\u540e\u5f97\u5230\u5bc6\u6587(Rn+1,Ln+1)<br \/>\n\u89e3\u5bc6(Rn+1,Ln+1)\u662f\u901a\u8fc7\u5982\u4e0b\u6b65\u9aa4\u6765\u5b8c\u6210\u7684\uff1a<br \/>\n\u4ee4i=n,n-1,\u2026,0<br \/>\nRi = Li+1<br \/>\nLi = Ri+1 ^ F(Li+1,Ki)<br \/>\n\u6700\u540e\u53c8\u5f97\u5230\u539f\u6765\u7684(L0,R0)\u4e86<\/p>\n<p>\u8fd9\u4e48\u8bf4\u53ef\u80fd\u4e0d\u597d\u7406\u89e3\uff0c\u770b\u4e0b\u56fe\uff08\u6765\u81eawikipedia)\u5c31\u6e05\u695a\u4e86\uff1a<\/p>\n<p>\u7b80\u5355\u5730\u8bf4\uff1a<br \/>\n\u5c31\u662f\u4e00\u79cd\u5206\u7ec4\u5bc6\u7801\uff0c\u4e00\u822c\u5206\u4e3a64\u4f4d\u4e00\u7ec4\uff0c\u4e00\u7ec4\u5206\u5de6\u53f3\u90e8\u5206\uff0c\u8fdb\u884c\u4e00\u822c\u4e3a16\u8f6e\u7684\u8fed\u4ee3\u8fd0\u7b97\uff0c\u6bcf\u6b21\u8fed\u4ee3\u5b8c\u540e\u4ea4\u6362\u5de6\u53f3\u4f4d\u7f6e\uff0c\u53ef\u4ee5\u81ea\u5df1\u8fdb\u884c\u8bbe\u8ba1\u7684\u6709:<br \/>\n\u5206\u7ec4\u5927\u5c0f<br \/>\n\u5bc6\u94a5\u957f\u5ea6<br \/>\n\u8f6e\u6b21\u6570<br \/>\n\u5b50\u5bc6\u94a5\u751f\u6210<br \/>\n\u8f6e\u51fd\u6570<\/p>\n<p>\u7136\u540e\u5e94\u8be5\u4e86\u89e3\u4e00\u4e0b<strong><a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fzh.wikipedia.org%2Fwiki%2F%E5%9D%97%E5%AF%86%E7%A0%81%E7%9A%84%E5%B7%A5%E4%BD%9C%E6%A8%A1%E5%BC%8F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">\u5757\u5bc6\u7801\u7684\u5de5\u4f5c\u6a21\u5f0f<\/a><\/strong>\uff1a<br \/>\nfrom wikipedia:<\/p>\n<blockquote><p>\u5bc6\u7801\u5b66\u4e2d\uff0c\u5757\u5bc6\u7801\u7684\u5de5\u4f5c\u6a21\u5f0f\u5141\u8bb8\u4f7f\u7528\u540c\u4e00\u4e2a\u5757\u5bc6\u7801\u5bc6\u94a5\u5bf9\u591a\u4e8e\u4e00\u5757\u7684\u6570\u636e\u8fdb\u884c\u52a0\u5bc6\uff0c\u5e76\u4fdd\u8bc1\u5176\u5b89\u5168\u6027\u3002[1][2] \u5757\u5bc6\u7801\u81ea\u8eab\u53ea\u80fd\u52a0\u5bc6\u957f\u5ea6\u7b49\u4e8e\u5bc6\u7801\u5757\u957f\u5ea6\u7684\u5355\u5757\u6570\u636e\uff0c\u82e5\u8981\u52a0\u5bc6\u53d8\u957f\u6570\u636e\uff0c\u5219\u6570\u636e\u5fc5\u987b\u5148\u88ab\u5212\u5206\u4e3a\u4e00\u4e9b\u5355\u72ec\u7684\u5bc6\u7801\u5757\u3002\u901a\u5e38\u800c\u8a00\uff0c\u6700\u540e\u4e00\u5757\u6570\u636e\u4e5f\u9700\u8981\u4f7f\u7528\u5408\u9002\u586b\u5145\u65b9\u5f0f\u5c06\u6570\u636e\u6269\u5c55\u5230\u7b26\u5408\u5bc6\u7801\u5757\u5927\u5c0f\u7684\u957f\u5ea6\u3002\u4e00\u79cd\u5de5\u4f5c\u6a21\u5f0f\u63cf\u8ff0\u4e86\u52a0\u5bc6\u6bcf\u4e00\u6570\u636e\u5757\u7684\u8fc7\u7a0b\uff0c\u5e76\u5e38\u5e38\u4f7f\u7528\u57fa\u4e8e\u4e00\u4e2a\u901a\u5e38\u79f0\u4e3a\u521d\u59cb\u5316\u5411\u91cf\u7684\u9644\u52a0\u8f93\u5165\u503c\u4ee5\u8fdb\u884c\u968f\u673a\u5316\uff0c\u4ee5\u4fdd\u8bc1\u5b89\u5168[1]\u3002<\/p>\n<p>\u5de5\u4f5c\u6a21\u5f0f\u4e3b\u8981\u7528\u6765\u8fdb\u884c\u52a0\u5bc6\u548c\u8ba4\u8bc1\u3002[1][3] \u5bf9\u52a0\u5bc6\u6a21\u5f0f\u7684\u7814\u7a76\u66fe\u7ecf\u5305\u542b\u6570\u636e\u7684\u5b8c\u6574\u6027\u4fdd\u62a4\uff0c\u5373\u5728\u67d0\u4e9b\u6570\u636e\u88ab\u4fee\u6539\u540e\u7684\u60c5\u51b5\u4e0b\u5bc6\u7801\u7684\u8bef\u5dee\u4f20\u64ad\u7279\u6027\u3002\u540e\u6765\u7684\u7814\u7a76\u5219\u5c06\u5b8c\u6574\u6027\u4fdd\u62a4\u4f5c\u4e3a\u53e6\u4e00\u4e2a\u5b8c\u5168\u4e0d\u540c\u7684\uff0c\u4e0e\u52a0\u5bc6\u65e0\u5173\u7684\u5bc6\u7801\u5b66\u76ee\u6807\u3002\u90e8\u5206\u73b0\u4ee3\u7684\u5de5\u4f5c\u6a21\u5f0f\u7528\u6709\u6548\u7684\u65b9\u6cd5\u5c06\u52a0\u5bc6\u548c\u8ba4\u8bc1\u7ed3\u5408\u8d77\u6765\uff0c\u79f0\u4e3a\u8ba4\u8bc1\u52a0\u5bc6\u6a21\u5f0f\u3002[2]<\/p>\n<p>\u867d\u7136\u5de5\u4f5c\u6a21\u5f0f\u901a\u5e38\u5e94\u7528\u4e8e\u5bf9\u79f0\u52a0\u5bc6[2]\uff0c\u5b83\u4ea6\u53ef\u4ee5\u5e94\u7528\u4e8e\u516c\u94a5\u52a0\u5bc6\uff0c\u4f8b\u5982\u5728\u539f\u7406\u4e0a\u5bf9RSA\u8fdb\u884c\u5904\u7406\uff0c\u4f46\u5728\u5b9e\u7528\u4e2d\uff0c\u516c\u94a5\u5bc6\u7801\u5b66\u901a\u5e38\u4e0d\u7528\u4e8e\u52a0\u5bc6\u8f83\u957f\u7684\u4fe1\u606f\uff0c\u800c\u662f\u4f7f\u7528\u6df7\u5408\u52a0\u5bc6\u65b9\u6848<\/p><\/blockquote>\n<p>\u4e00\u822c\u6765\u8bf4\u5e38\u7528\u7684\u52a0\u5bc6\u6a21\u5f0f\u6709\u8fd9\u4e48\u51e0\u79cd\uff1a<\/p>\n<blockquote><p>\u7535\u5b50\u5bc6\u7801\u672c\uff08ECB\uff09<br \/>\n\u5bc6\u7801\u5757\u94fe\u63a5\uff08CBC\uff09\uff1a\u5728CBC\u6a21\u5f0f\u4e2d\uff0c\u6bcf\u4e2a\u5e73\u6587\u5757\u5148\u4e0e\u524d\u4e00\u4e2a\u5bc6\u6587\u5757\u8fdb\u884c\u5f02\u6216\u540e\uff0c\u518d\u8fdb\u884c\u52a0\u5bc6\u3002\u5728\u8fd9\u79cd\u65b9\u6cd5\u4e2d\uff0c\u6bcf\u4e2a\u5bc6\u6587\u5757\u90fd\u4f9d\u8d56\u4e8e\u5b83\u524d\u9762\u7684\u6240\u6709\u5e73\u6587\u5757\u3002\u540c\u65f6\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6bcf\u6761\u6d88\u606f\u7684\u552f\u4e00\u6027\uff0c\u5728\u7b2c\u4e00\u4e2a\u5757\u4e2d\u9700\u8981\u4f7f\u7528\u521d\u59cb\u5316\u5411\u91cf\u3002<br \/>\n\u586b\u5145\u5bc6\u7801\u5757\u94fe\u63a5\uff08PCBC\uff09<br \/>\n\u5bc6\u6587\u53cd\u9988\uff08CFB\uff09<br \/>\n\u8f93\u51fa\u53cd\u9988\uff08OFB\uff09<br \/>\n\u8ba1\u6570\u5668\u6a21\u5f0f\uff08CTR\uff09<\/p><\/blockquote>\n<p><span id=\"OSC_h3_2\"><\/span><\/p>\n<h3 id=\"h3_2\">\u521d\u59cb\u5316\u5411\u91cf\uff08IV\uff09<\/h3>\n<blockquote><p>\u521d\u59cb\u5316\u5411\u91cf\uff08IV\uff0cInitialization Vector\uff09\u662f\u8bb8\u591a\u5de5\u4f5c\u6a21\u5f0f\u4e2d\u7528\u4e8e\u968f\u673a\u5316\u52a0\u5bc6\u7684\u4e00\u5757\u6570\u636e\uff0c\u56e0\u6b64\u53ef\u4ee5\u7531\u76f8\u540c\u7684\u660e\u6587\uff0c\u76f8\u540c\u7684\u5bc6\u94a5\u4ea7\u751f\u4e0d\u540c\u7684\u5bc6\u6587\uff0c\u800c\u65e0\u9700\u91cd\u65b0\u4ea7\u751f\u5bc6\u94a5\uff0c\u907f\u514d\u4e86\u901a\u5e38\u76f8\u5f53\u590d\u6742\u7684\u8fd9\u4e00\u8fc7\u7a0b\u3002<\/p>\n<p>\u521d\u59cb\u5316\u5411\u91cf\u4e0e\u5bc6\u94a5\u76f8\u6bd4\u6709\u4e0d\u540c\u7684\u5b89\u5168\u6027\u9700\u6c42\uff0c\u56e0\u6b64IV\u901a\u5e38\u65e0\u987b\u4fdd\u5bc6\uff0c\u7136\u800c\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e2d\uff0c\u4e0d\u5e94\u5f53\u5728\u4f7f\u7528\u540c\u4e00\u5bc6\u94a5\u7684\u60c5\u51b5\u4e0b\u4e24\u6b21\u4f7f\u7528\u540c\u4e00\u4e2aIV\u3002\u5bf9\u4e8eCBC\u548cCFB\uff0c\u91cd\u7528IV\u4f1a\u5bfc\u81f4\u6cc4\u9732\u5e73\u6587\u9996\u4e2a\u5757\u7684\u67d0\u4e9b\u4fe1\u606f\uff0c\u4ea6\u5305\u62ec\u4e24\u4e2a\u4e0d\u540c\u6d88\u606f\u4e2d\u76f8\u540c\u7684\u524d\u7f00\u3002\u5bf9\u4e8eOFB\u548cCTR\u800c\u8a00\uff0c\u91cd\u7528IV\u4f1a\u5bfc\u81f4\u5b8c\u5168\u5931\u53bb\u5b89\u5168\u6027\u3002\u53e6\u5916\uff0c\u5728CBC\u6a21\u5f0f\u4e2d\uff0cIV\u5728\u52a0\u5bc6\u65f6\u5fc5\u987b\u662f\u65e0\u6cd5\u9884\u6d4b\u7684\uff1b\u7279\u522b\u7684\uff0c\u5728\u8bb8\u591a\u5b9e\u73b0\u4e2d\u4f7f\u7528\u7684\u4ea7\u751fIV\u7684\u65b9\u6cd5\uff0c\u4f8b\u5982SSL2.0\u4f7f\u7528\u7684\uff0c\u5373\u91c7\u7528\u4e0a\u4e00\u4e2a\u6d88\u606f\u7684\u6700\u540e\u4e00\u5757\u5bc6\u6587\u4f5c\u4e3a\u4e0b\u4e00\u4e2a\u6d88\u606f\u7684IV\uff0c\u662f\u4e0d\u5b89\u5168\u7684[12]\u3002<\/p><\/blockquote>\n<p><span id=\"OSC_h3_3\"><\/span><\/p>\n<h3 id=\"h3_3\">\u586b\u5145<\/h3>\n<blockquote><p>\u5757\u5bc6\u7801\u53ea\u80fd\u5bf9\u786e\u5b9a\u957f\u5ea6\u7684\u6570\u636e\u5757\u8fdb\u884c\u5904\u7406\uff0c\u800c\u6d88\u606f\u7684\u957f\u5ea6\u901a\u5e38\u662f\u53ef\u53d8\u7684\u3002\u56e0\u6b64\u90e8\u5206\u6a21\u5f0f\uff08\u5373ECB\u548cCBC\uff09\u9700\u8981\u6700\u540e\u4e00\u5757\u5728\u52a0\u5bc6\u524d\u8fdb\u884c\u586b\u5145\u3002\u6709\u6570\u79cd\u586b\u5145\u65b9\u6cd5\uff0c\u5176\u4e2d\u6700\u7b80\u5355\u7684\u4e00\u79cd\u662f\u5728\u5e73\u6587\u7684\u6700\u540e\u586b\u5145\u7a7a\u5b57\u7b26\u4ee5\u4f7f\u5176\u957f\u5ea6\u4e3a\u5757\u957f\u5ea6\u7684\u6574\u6570\u500d\uff0c\u4f46\u5fc5\u987b\u4fdd\u8bc1\u53ef\u4ee5\u6062\u590d\u5e73\u6587\u7684\u539f\u59cb\u957f\u5ea6\uff1b\u4f8b\u5982\uff0c\u82e5\u5e73\u6587\u662fC\u8bed\u8a00\u98ce\u683c\u7684\u5b57\u7b26\u4e32\uff0c\u5219\u53ea\u6709\u4e32\u5c3e\u4f1a\u6709\u7a7a\u5b57\u7b26\u3002\u7a0d\u5fae\u590d\u6742\u4e00\u70b9\u7684\u65b9\u6cd5\u5219\u662f\u539f\u59cb\u7684DES\u4f7f\u7528\u7684\u65b9\u6cd5\uff0c\u5373\u5728\u6570\u636e\u540e\u6dfb\u52a0\u4e00\u4e2a1\u4f4d\uff0c\u518d\u6dfb\u52a0\u8db3\u591f\u76840\u4f4d\u76f4\u5230\u6ee1\u8db3\u5757\u957f\u5ea6\u7684\u8981\u6c42\uff1b\u82e5\u6d88\u606f\u957f\u5ea6\u521a\u597d\u7b26\u5408\u5757\u957f\u5ea6\uff0c\u5219\u6dfb\u52a0\u4e00\u4e2a\u586b\u5145\u5757\u3002\u6700\u590d\u6742\u7684\u5219\u662f\u9488\u5bf9CBC\u7684\u65b9\u6cd5\uff0c\u4f8b\u5982\u5bc6\u6587\u7a83\u53d6\uff0c\u6b8b\u5757\u7ec8\u7ed3\u7b49\uff0c\u4e0d\u4f1a\u4ea7\u751f\u989d\u5916\u7684\u5bc6\u6587\uff0c\u4f46\u4f1a\u589e\u52a0\u4e00\u4e9b\u590d\u6742\u5ea6\u3002\u5e03\u9c81\u65af\u00b7\u65bd\u5948\u5c14\u548c\u5c3c\u5c14\u65af\u00b7\u5f17\u683c\u68ee\u63d0\u51fa\u4e86\u4e24\u79cd\u7b80\u5355\u7684\u53ef\u80fd\u6027\uff1a\u6dfb\u52a0\u4e00\u4e2a\u503c\u4e3a128\u7684\u5b57\u8282\uff08\u5341\u516d\u8fdb\u5236\u768480\uff09\uff0c\u518d\u4ee50\u5b57\u8282\u586b\u6ee1\u6700\u540e\u4e00\u4e2a\u5757\uff1b\u6216\u5411\u6700\u540e\u4e00\u4e2a\u5757\u586b\u5145n\u4e2a\u503c\u5747\u4e3an\u7684\u5b57\u8282[13]\u3002<\/p>\n<p>CFB\uff0cOFB\u548cCTR\u6a21\u5f0f\u4e0d\u9700\u8981\u5bf9\u957f\u5ea6\u4e0d\u4e3a\u5bc6\u7801\u5757\u5927\u5c0f\u6574\u6570\u500d\u7684\u6d88\u606f\u8fdb\u884c\u7279\u522b\u7684\u5904\u7406\u3002\u56e0\u4e3a\u8fd9\u4e9b\u6a21\u5f0f\u662f\u901a\u8fc7\u5bf9\u5757\u5bc6\u7801\u7684\u8f93\u51fa\u4e0e\u5e73\u6587\u8fdb\u884c\u5f02\u6216\u5de5\u4f5c\u7684\u3002\u6700\u540e\u4e00\u4e2a\u5e73\u6587\u5757\uff08\u53ef\u80fd\u662f\u4e0d\u5b8c\u6574\u7684\uff09\u4e0e\u5bc6\u94a5\u6d41\u5757\u7684\u524d\u51e0\u4e2a\u5b57\u8282\u5f02\u6216\u540e\uff0c\u4ea7\u751f\u4e86\u4e0e\u8be5\u5e73\u6587\u5757\u5927\u5c0f\u76f8\u540c\u7684\u5bc6\u6587\u5757\u3002\u6d41\u5bc6\u7801\u7684\u8fd9\u4e2a\u7279\u6027\u4f7f\u5f97\u5b83\u4eec\u53ef\u4ee5\u5e94\u7528\u5728\u9700\u8981\u5bc6\u6587\u548c\u5e73\u6587\u6570\u636e\u957f\u5ea6\u4e25\u683c\u76f8\u7b49\u7684\u573a\u5408\uff0c\u4e5f\u53ef\u4ee5\u5e94\u7528\u5728\u4ee5\u6d41\u5f62\u5f0f\u4f20\u8f93\u6570\u636e\u800c\u4e0d\u4fbf\u4e8e\u8fdb\u884c\u586b\u5145\u7684\u573a\u5408\u3002<\/p><\/blockquote>\n<p>\u53e6\u5916\u5728mcrypt\u7684man\u6587\u6863\u91cc\u4e5f\u627e\u5230\u4e86\u52a0\u5bc6\u6a21\u5f0f\u7684\u4ecb\u7ecd\uff1a<\/p>\n<p><span id=\"OSC_h3_4\"><\/span><\/p>\n<h3 id=\"h3_4\">\u52a0\u5bc6\u6a21\u5f0f<\/h3>\n<blockquote><p>modes of encryption:<br \/>\n<strong>ECB<\/strong>: The Electronic CodeBook mode. It is the simplest mode to use with a block cipher. Encrypts each block independently.<\/p>\n<p><strong>CBC<\/strong>: The Cipher Block Chaining mode. It is better than ECB since the plaintext is XOR\u2019ed with the previous ciphertext. A random block is placed as the first block so the same block or messages always encrypt to something different. (This is the default mode)<\/p>\n<p><strong>CFB<\/strong>: The Cipher-Feedback Mode (in 8bit). This is a self-synchronizing stream cipher implemented from a block cipher.<\/p>\n<p><strong>OFB<\/strong>: The Output-Feedback Mode (in 8bit). This is a synchronous stream cipher implemented from a block cipher. It is intended for use in noisy lines, because corrupted ciphertext blocks do not corrupt the plaintext blocks that follow. Insecure (because used in 8bit mode) so I recommend against using it. Added just for completeness.<\/p>\n<p><strong>nOFB<\/strong>: The Output-Feedback Mode (in nbit). n Is the size of the block of the algorithm. This is a synchronous stream cipher implemented from a block cipher. It is intended for use in noisy lines, because corrupted ciphertext blocks do not corrupt the plaintext blocks that follow.<\/p><\/blockquote>\n<p>via http:\/\/mcrypt.hellug.gr\/mcrypt\/mcrypt.1.html<br \/>\nBTW,The author of mcrypt and libmcrypt is\u00a0<strong>Nikos Mavroyanopoulos<\/strong>.<\/p>\n<p><span id=\"OSC_h3_5\"><\/span><\/p>\n<h3 id=\"h3_5\">\u5206\u5757\u5927\u5c0f<\/h3>\n<p><a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FBlock_size_%28cryptography%29\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Block size<\/a><\/p>\n<blockquote><p>\u73b0\u4ee3\u52a0\u5bc6\u7b97\u6cd5\u4e2d\uff0c\u5bf9\u79f0\u5bc6\u94a5\u7b97\u6cd5\u901a\u5e38\u88ab\u5206\u4e3astream ciphers\u548cblock ciphers\u3002\u5206\u5757\u5bc6\u7801\u5904\u7406\u56fa\u5b9a\u957f\u5ea6\u7684\u5b57\u7b26\u4e32\u4f4d\u6570(bit)\u3002\u8fd9\u4e2a\u6bd4\u7279\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u5fc5\u987b\u548c\u5206\u5757\u5927\u5c0f\u4e00\u6837\u957f\u3002\u8f93\u5165\uff08\u660e\u6587\uff09\u548c\u8f93\u51fa\uff08\u5bc6\u6587\uff09\u90fd\u662f\u540c\u6837\u957f\u5ea6\u7684\u3002\u8f93\u51fa\u4e0d\u80fd\u6bd4\u8f93\u5165\u77ed\u2014\u2014\u8fd9\u662f\u9075\u5faa<a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPigeonhole_principle\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Pigeonhole principle<\/a>\uff08\u9e3d\u5de2\u539f\u7406\uff0c\u53c8\u540d\u72c4\u5229\u514b\u96f7\u62bd\u5c49\u539f\u7406\u3001\u9e3d\u7b3c\u539f\u7406\uff09\u548c\u5bc6\u7801\u5fc5\u987b\u662f\u53ef\u9006\u7684\u4e8b\u5b9e\u2014\u2014\u7136\u800c\uff0c\u8f93\u51fa\u6bd4\u8f93\u5165\u66f4\u957f\u53c8\u662f\u4e0d\u53ef\u53d6\u7684\u3002<\/p><\/blockquote>\n<p>\u9e3d\u5de2\u539f\u7406\uff1a<\/p>\n<blockquote><p>\u5176\u4e2d\u4e00\u79cd\u7b80\u5355\u7684\u8868\u8ff0\u6cd5\u4e3a\uff1a<br \/>\n\u82e5\u6709n\u4e2a\u7b3c\u5b50\u548cn+1\u53ea\u9e3d\u5b50\uff0c\u6240\u6709\u7684\u9e3d\u5b50\u90fd\u88ab\u5173\u5728\u9e3d\u7b3c\u91cc\uff0c\u90a3\u4e48\u81f3\u5c11\u6709\u4e00\u4e2a\u7b3c\u5b50\u6709\u81f3\u5c112\u53ea\u9e3d\u5b50\u3002<br \/>\n\u53e6\u4e00\u79cd\u4e3a\uff1a<br \/>\n\u82e5\u6709n\u4e2a\u7b3c\u5b50\u548ckn+1\u53ea\u9e3d\u5b50\uff0c\u6240\u6709\u7684\u9e3d\u5b50\u90fd\u88ab\u5173\u5728\u9e3d\u7b3c\u91cc\uff0c\u90a3\u4e48\u81f3\u5c11\u6709\u4e00\u4e2a\u7b3c\u5b50\u6709\u81f3\u5c11k+1\u53ea\u9e3d\u5b50\u3002<br \/>\n\u62c9\u59c6\u9f50\u5b9a\u7406\u662f\u6b64\u539f\u7406\u7684\u63a8\u5e7f\u3002<\/p><\/blockquote>\n<p>\u901a\u4fd7\u70b9\u8bf4\uff1a<br \/>\n10\u53ea\u9e3d\u5b50\u653e\u8fdb9\u4e2a\u9e3d\u7b3c\uff0c\u90a3\u4e48\u4e00\u5b9a\u6709\u4e00\u4e2a\u9e3d\u7b3c\u653e\u8fdb\u4e86\u81f3\u5c11\u4e24\u53ea\u9e3d\u5b50\u3002<\/p>\n<p>S-box (Substitution-box,\u66ff\u6362\u76d2)<br \/>\n\u5728\u5206\u5757\u5bc6\u7801\u4e2d\uff0cS-box\u901a\u5e38\u88ab\u7528\u6765\u63a9\u76d6\u5bc6\u94a5\u548c\u5bc6\u6587\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<blockquote><p>In general, an S-Box takes some number of input bits, m, and transforms them into some number of output bits, n: an m\u00d7n S-Box can be implemented as a lookup table with 2m words of n bits each. Fixed tables are normally used, as in the Data Encryption Standard (DES), but in some ciphers the tables are generated dynamically from the key; e.g. the Blowfish and the Twofish encryption algorithms. Bruce Schneier describes IDEA\u2019s modular multiplication step as a key-dependent S-Box.<\/p><\/blockquote>\n<p><a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FInternational_Data_Encryption_Algorithm\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">IDEA(International Data Encryption Algorithm)<\/a><\/p>\n<p><a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FRijndael_S-box\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Rijndael S-box<\/a><\/p>\n<p>\u7b97\u6cd5\u8bf4\u660e\uff1a<br \/>\nBlowFish \u4f7f\u7528\u4e86\u4e24\u4e2abox,\u9664\u4e86\u8457\u540d\u7684S-box\uff0c\u8fd8\u6709\u4e00\u4e2ap-box<br \/>\npbox\u670918\u4e2aunsigned long\u5143\u7d20<br \/>\nsbox\u67094\u00d7256\u4e2aunsigned long\u5143\u7d20<br \/>\nBlowFish\u7b97\u6cd5\u4e2d\uff0c\u6709\u4e00\u4e2a\u6838\u5fc3\u52a0\u5bc6\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u8f93\u516564\u4f4d\u4fe1\u606f\uff0c\u8fd0\u7b97\u540e\uff0c \u4ee564\u4f4d\u5bc6\u6587\u7684\u5f62\u5f0f\u8f93\u51fa\u3002 \u7528BlowFish\u7b97\u6cd5\u52a0\u5bc6\u4fe1\u606f\uff0c\u9700\u8981\u4e24\u4e2a\u8fc7\u7a0b\uff1a<br \/>\n\u8fd9\u91cc\u6211\u770b\u7684\u6e90\u7801\u662f<a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPaul_Kocher\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Paul Kocher<\/a>\u7684C\u8bed\u8a00\u7248\u672c\u3002<br \/>\n\u6e90\u7801\u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fwww.schneier.com%2Fblowfish-download.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">http:\/\/www.schneier.com\/blowfish-download.html<\/a><\/p>\n<p>1.\u5bc6\u94a5\u9884\u5904\u7406<br \/>\n2.\u4fe1\u606f\u52a0\u5bc6<\/p>\n<p>\u7ed3\u6784\u4f53\u5b9a\u4e49\uff1a<\/p>\n<pre>typedef struct {\r\n  unsigned long P[16 + 2];\r\n  unsigned long S[4][256];\r\n} BLOWFISH_CTX;<\/pre>\n<p>1.\u5bc6\u94a5\u9884\u5904\u7406<br \/>\nBlowFish\u7b97\u6cd5\u7684\u6e90\u5bc6\u94a5\u2014\u2014pbox\u548csbox\u662f\u56fa\u5b9a\u7684\u3002\u6b64pbox\u548csbox\u7684\u503c\u6765\u81ea<a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fwww.super-computing.org%2Fpi-hexa_current.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">PI\u7684\u5341\u516d\u8fdb\u5236\u6570\u5b57\u503c<\/a>\uff0c\u4f7f\u7528\u8fd9\u4e9b\u6570\u7684\u539f\u56e0\u662f\u8fd9\u4e9b\u6570\u770b\u4e0d\u51fa\u6709\u4ec0\u4e48\u660e\u663e\u7684\u89c4\u5f8b\u3002(<a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPi\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">PI<\/a>)<br \/>\n\u8fd9\u91cc\u6458\u53d61-500\u4f4d\uff1a<\/p>\n<pre>3.243F6A8885 A308D31319 8A2E037073 44A4093822 299F31D008\r\n  2EFA98EC4E 6C89452821 E638D01377 BE5466CF34 E90C6CC0AC\r\n  29B7C97C50 DD3F84D5B5 B547091792 16D5D98979 FB1BD1310B\r\n  A698DFB5AC 2FFD72DBD0 1ADFB7B8E1 AFED6A267E 96BA7C9045\r\n  F12C7F9924 A19947B391 6CF70801F2 E2858EFC16 636920D871\r\n  574E69A458 FEA3F4933D 7E0D95748F 728EB65871 8BCD588215\r\n  4AEE7B54A4 1DC25A59B5 9C30D5392A F26013C5D1 B023286085\r\n  F0CA417918 B8DB38EF8E 79DCB0603A 180E6C9E0E 8BB01E8A3E\r\n  D71577C1BD 314B2778AF 2FDA55605C 60E65525F3 AA55AB9457\r\n  48986263E8 144055CA39 6A2AAB10B6 B4CC5C3411 41E8CEA154<\/pre>\n<pre>void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen) {\r\n  int i, j, k;\r\n  unsigned long data, datal, datar;\r\n\r\n  for (i = 0; i &lt; 4; i++) {\r\n    for (j = 0; j &lt; 256; j++)\r\n      ctx-&gt;S[i][j] = ORIG_S[i][j];\r\n  }\r\n\r\n  j = 0;\r\n  for (i = 0; i &lt; N + 2; ++i) {\r\n    data = 0x00000000;\r\n    for (k = 0; k &lt; 4; ++k) {\r\n      data = (data &lt;&lt; 8) | key[j];\r\n      j = j + 1;\r\n      if (j &gt;= keyLen)\r\n        j = 0;\r\n    }\r\n    ctx-&gt;P[i] = ORIG_P[i] ^ data;\r\n  }\r\n\r\n  datal = 0x00000000;\r\n  datar = 0x00000000;\r\n\r\n  for (i = 0; i &lt; N + 2; i += 2) {\r\n    Blowfish_Encrypt(ctx, &amp;datal, &amp;datar);\r\n    ctx-&gt;P[i] = datal;\r\n    ctx-&gt;P[i + 1] = datar;\r\n  }\r\n\r\n  for (i = 0; i &lt; 4; ++i) {\r\n    for (j = 0; j &lt; 256; j += 2) {\r\n      Blowfish_Encrypt(ctx, &amp;datal, &amp;datar);\r\n      ctx-&gt;S[i][j] = datal;\r\n      ctx-&gt;S[i][j + 1] = datar;\r\n    }\r\n  }\r\n}<\/pre>\n<p>\u6211\u4eec\u8981\u52a0\u5bc6\u4e00\u4e2a\u4fe1\u606f\uff0c<br \/>\n\u9700\u8981\u81ea\u5df1\u9009\u62e9\u4e00\u4e2akey\uff0c\u7528\u8fd9\u4e2akey\u5bf9pbox\u548csbox\u8fdb\u884c\u53d8\u6362\uff0c\u5f97\u5230\u4e0b\u4e00\u6b65\u4fe1\u606f\u52a0\u5bc6<br \/>\n\u6240\u8981\u7528\u7684pbox\u548csbox\u3002<br \/>\n\u5177\u4f53\u7684\u53d8\u5316\u7b97\u6cd5\u5982\u4e0b\uff1a<br \/>\n\u7528\u539fsbox: ORIG_S \u586b\u5145 sbox<\/p>\n<p>\u7136\u540e\uff0c\u6bcf\u6b21\u53d6key\u4e0edata\u8fdb\u884c\u8fd0\u7b97\uff0c\u8fd0\u7b97\u540e\u7684\u7ed3\u679c\u9001\u7ed9pbox<br \/>\n\u8fd0\u7b97\u8fc7\u7a0b\u662f\u8fd9\u6837\u7684\uff1a<br \/>\n\u8fdb\u884cN+2\u6b21\u8fd0\u7b97\uff08N=16),<br \/>\n\u4ee4 32\u4f4d\u65e0\u7b26\u53f7data\u4e3a0,\u7531\u4e8eKey\u662funsigned char\u7c7b\u578b\u7684\uff0c\u6bcf\u6b21\u5bf9data\u5de6\u79fb8\u4f4d(\u4e00\u4e2a\u5b57\u8282)\u4e4b\u540e\u4e0e<br \/>\n\u76f8\u5e94\u7684key\u76f8\u6216\uff08\u5373\u76f8\u52a0\uff09\uff0c\u5f53key\u957f\u5ea6\u5c0f\u4e8e4\u65f6\uff0c\u5faa\u73af\u4f7f\u7528Key\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u7528bf_encypt\u52a0\u5bc6\u4e00\u4e2a\u51680\u768464\u4f4d\u4fe1\u606f\uff08\u5206\u4e3adatal\u548cdatar,\u540432\u4f4d\uff09<br \/>\n\u7528\u8f93\u51fa\u7684\u7ed3\u679cdatal\u548cdatar\u5206\u522b\u66ff\u6362pbox[0]\u548cpbox[1]<br \/>\n\u7136\u540e\uff0c\u7ee7\u7eed\u52a0\u5bc6datal\u548cdatar,\u7528\u8f93\u51fa\u7ed3\u679c\u66ff\u6362pbox[2]\u548cpbox[3]<br \/>\n\u2026\u2026<br \/>\n\u8fd9\u6837\u5faa\u73af18\u6b21\uff0c\u628apbox\u5168\u90e8\u66ff\u6362\u5b8c\u6210\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u662f\u5bf9sbox\u7684\u66ff\u6362\u4e86\u3002<br \/>\n\u8fd9\u6b21\u603b\u5171\u662f\u5faa\u73af4\u00d7256\u6b21\uff0c\u6bcf\u6b21\u5faa\u73af\u7684\u8fc7\u7a0b\u4e0e\u4e0a\u9762\u7684\u4e00\u6837\u3002<br \/>\n\u4e0d\u8fc7\u8fd9\u91cc\u7528\u7684datal\u548cdatar\u5c31\u662f\u4e0a\u9762\u8fd0\u7b97\u8fc7\u540e\u7684datal\u548cdatar.<\/p>\n<p>2.\u4fe1\u606f\u52a0\u5bc6<br \/>\n\u63a5\u4e0b\u6765\u770b\u8fd9\u4e2a\u52a0\u5bc6\u51fd\u6570\uff0c\u4e0a\u9762\u7684\u521d\u59cb\u5316\u8fc7\u7a0b\u5df2\u7ecf\u7528\u5230\u5b83\u4e86\u3002<\/p>\n<pre>void Blowfish_Encrypt(BLOWFISH_CTX *ctx, unsigned long *xl, unsigned long *xr){\r\n  unsigned long  Xl;\r\n  unsigned long  Xr;\r\n  unsigned long  temp;\r\n  short       i;\r\n\r\n  Xl = *xl;\r\n  Xr = *xr;\r\n\r\n  for (i = 0; i &lt; N; ++i) {\r\n    Xl = Xl ^ ctx-&gt;P[i];\r\n    Xr = F(ctx, Xl) ^ Xr;\r\n\r\n    temp = Xl;\r\n    Xl = Xr;\r\n    Xr = temp;\r\n  }\r\n\r\n  temp = Xl;\r\n  Xl = Xr;\r\n  Xr = temp;\r\n\r\n  Xr = Xr ^ ctx-&gt;P[N];\r\n  Xl = Xl ^ ctx-&gt;P[N + 1];\r\n\r\n  *xl = Xl;\r\n  *xr = Xr;\r\n}<\/pre>\n<p>\u4e0e\u4e0a\u9762\u8bf4\u7684Feistel \u5bc6\u7801\u7684\u8fd0\u7b97\u8fc7\u7a0b\u662f\u4e00\u6837\u7684\uff1a<br \/>\n\u628a64\u4f4d\u7684\u660e\u6587\u5206\u4e3al\u548cr<br \/>\n\u8fdb\u884c16\u8f6e\u8fd0\u7b97\uff1a<br \/>\n\u4ee4i=0,1,2,3,\u2026,N-1<br \/>\nXl = Xl ^ ctx-&gt;P[i];<br \/>\nXr = F(ctx, Xl) ^ Xr;<br \/>\n\u82e5i&lt;N,\u4ea4\u6362Xl\u548cXr\u7684\u503c\u7ee7\u7eed\u505a\u4e0a\u8ff0\u8fd0\u7b97\u3002<br \/>\n16\u8f6e\u8fd0\u7b97\u5b8c\u4e86\u4e4b\u540e\uff0c\u518d\u505a\u4e00\u6b21Xl\u4e0eXr\u7684\u4ea4\u6362\uff0c\u56e0\u4e3a\u7b2c16\u6b21\u8fd0\u7b97\u5b8c\u4e86\u4e4b\u540e\uff0c\u5b9e\u9645\u4e0a<br \/>\n\u6ca1\u6709\u518d\u505a\u8fd0\u7b97\u4e86\uff0c\u4f46\u662fXl\u4e0eXr\u8fd8\u662f\u4ea4\u6362\u4e86\uff0c\u56e0\u6b64\uff0c\u5f97\u6362\u56de\u6765\u3002<\/p>\n<p>\u7136\u540e\uff0cXr = Xr ^ ctx-&gt;P[N];<br \/>\nXl = Xl ^ ctx-&gt;P[N + 1];<br \/>\n\u73b0\u5728\u7684Xl\u548cXr\u5c31\u662f\u52a0\u5bc6\u540e\u7684\u6570\u636e\u4e86\u3002<br \/>\n\u52a0\u5bc6\u8fc7\u7a0b\u56fe\u89e3\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/static.oschina.net\/uploads\/space\/2018\/0115\/174108_K6Ky_3664884.png\" width=\"166\" height=\"35\" \/><\/p>\n<p>\u8fd9\u52a0\u5bc6\u8fc7\u7a0b\u4e2d\u7528\u5230\u4e86F\u53d8\u6362\uff1a<\/p>\n<pre>static unsigned long F(BLOWFISH_CTX *ctx, unsigned long x) {\r\n   unsigned short a, b, c, d;\r\n   unsigned long  y;\r\n\r\n   d = (unsigned short)(x &amp; 0xFF);\r\n   x &gt;&gt;= 8;\r\n   c = (unsigned short)(x &amp; 0xFF);\r\n   x &gt;&gt;= 8;\r\n   b = (unsigned short)(x &amp; 0xFF);\r\n   x &gt;&gt;= 8;\r\n   a = (unsigned short)(x &amp; 0xFF);\r\n   y = ctx-&gt;S[0][a] + ctx-&gt;S[1][b];\r\n   y = y ^ ctx-&gt;S[2][c];\r\n   y = y + ctx-&gt;S[3][d];\r\n\r\n   return y;\r\n}<\/pre>\n<p>\u8fd9\u4e2a\u53d8\u6362\u662f\u8fd9\u6837\u7684\uff1a<br \/>\n\u5b83\u63a5\u6536\u4e00\u4e2a32\u4f4d\u7684\u6570\u636e\uff0c\u7136\u540e\u4ece\u9ad8\u4f4d\u5230\u4f4e\u4f4d\u5206\u4e3a\u56db\u6bb5\uff0c\u6bcf\u6bb58\u4f4d\uff0c\u4f9d\u6b21\u7ed9<br \/>\na,b,c,d<br \/>\n\u53d6sbox[0][a]+sbox[1][b]\uff0c\u76f8\u52a0\u540e\u7684\u7ed3\u679c\u518d\u4e0esbox[2][c]\u505a\u5f02\u6216\u8fd0\u7b97\uff0c<br \/>\n\u5f97\u51fa\u7684\u7ed3\u679c\u518d\u52a0\u4e0asbox[3][d]<br \/>\n\u7531\u4e8esbox\u7684\u5143\u7d20\u90fd\u662f32\u4f4d\u7684\uff0c\u56e0\u6b64\uff0cF\u53d8\u6362\u540e\u7684\u8f93\u51fa\u4e5f\u662f32\u4f4d\u7684\u3002<br \/>\n\u8f6e\u51fd\u6570\u56fe\u89e3\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/static.oschina.net\/uploads\/space\/2018\/0115\/174124_94U5_3664884.png\" width=\"157\" height=\"34\" \/><\/p>\n<p>\u89e3\u5bc6\u51fd\u6570\uff1a<br \/>\n\u53ef\u4ee5\u770b\u5230\u89e3\u5bc6\u51fd\u6570\u4e0e\u52a0\u5bc6\u51fd\u6570\u975e\u5e38\u7684\u76f8\u4f3c\uff0c\u53ea\u662f\u628ap0,p1,\u2026,p17 \u9006\u5e8f\u4f7f\u7528\uff1a<\/p>\n<pre>void Blowfish_Decrypt(BLOWFISH_CTX *ctx, unsigned long *xl, unsigned long *xr){\r\n  unsigned long  Xl;\r\n  unsigned long  Xr;\r\n  unsigned long  temp;\r\n  short       i;\r\n\r\n  Xl = *xl;\r\n  Xr = *xr;\r\n\r\n  for (i = N + 1; i &gt; 1; --i) {\r\n    Xl = Xl ^ ctx-&gt;P[i];\r\n    Xr = F(ctx, Xl) ^ Xr;\r\n\r\n    \/* Exchange Xl and Xr *\/\r\n    temp = Xl;\r\n    Xl = Xr;\r\n    Xr = temp;\r\n  }\r\n\r\n  \/* Exchange Xl and Xr *\/\r\n  temp = Xl;\r\n  Xl = Xr;\r\n  Xr = temp;\r\n\r\n  Xr = Xr ^ ctx-&gt;P[1];\r\n  Xl = Xl ^ ctx-&gt;P[0];\r\n\r\n  *xl = Xl;\r\n  *xr = Xr;\r\n}<\/pre>\n<p>\u5173\u4e8eBlowFish \u5bc6\u7801\uff0c\u4e2a\u4eba\u8ba4\u4e3a\u53ef\u4ee5\u628a\u5b83\u7406\u89e3\u4e3a\u4e00\u79cd\u590d\u6742\u7684<a href=\"http:\/\/ihacklog.com\/l.php?url=http%3A%2F%2Fzh.wikipedia.org%2Fwiki%2F%E5%BC%82%E6%88%96%E5%AF%86%E7%A0%81\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">\u5f02\u6216\u5bc6\u7801<\/a>,\u5f02\u6216\u8fd0\u7b97\u7684\u89c4\u5f8b\uff1a<\/p>\n<pre>A ^ 0 = A\r\nA ^ A = 0\r\n(A ^ B) ^ C = A ^ (B ^ C)\r\n(B ^ A) ^ A = B ^ 0 = B<\/pre>\n<p>\u6309\u8fd9\u79cd\u903b\u8f91\uff0c\u6587\u672c\u5e8f\u5217\u7684\u6bcf\u4e2a\u5b57\u7b26\u53ef\u4ee5\u901a\u8fc7\u4e0e\u7ed9\u5b9a\u7684\u5bc6\u94a5\u8fdb\u884c\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u6765\u52a0\u5bc6\u3002\u5982\u679c\u8981\u89e3\u5bc6\uff0c\u53ea\u9700\u8981\u5c06\u52a0\u5bc6\u5f8c\u7684\u7ed3\u679c\u4e0e\u5bc6\u94a5\u518d\u6b21\u8fdb\u884c\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u5373\u53ef\u3002<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740 Blowfish\u662f1993\u5e74\u5e03<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[119],"class_list":["post-4182","post","type-post","status-publish","format-standard","hentry","tag-03-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/4182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=4182"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/4182\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=4182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=4182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=4182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}