{"id":513,"date":"2011-03-04T11:02:24","date_gmt":"2011-03-04T03:02:24","guid":{"rendered":"http:\/\/j178.mtgbb.com\/?p=513"},"modified":"2011-03-04T23:47:18","modified_gmt":"2011-03-04T15:47:18","slug":"513","status":"publish","type":"post","link":"https:\/\/j178.mtgbb.com\/?p=513","title":{"rendered":"XOR \u52a0\u3001\u89e3\u5bc6"},"content":{"rendered":"<p>XOR \u70ba\u52a0\u89e3\u5bc6\u7684\u4e00\u7a2e\u4f5c\u6cd5<\/p>\n<p>\u4ee5\u4e0b\u7bc4\u4f8b\u70ba\u7528 php \u5be6\u4f5c\u7684\u7bc4\u4f8b:<br \/>\n(Notice: \u70ba\u4e86\u7db2\u8def\u50b3\u8f38, \u7279\u5225\u5c07\u7de8\u78bc\u5f8c\u5b57\u4e32\u8f49\u70ba ascii \u6578\u5b57 (\u6bcf\u500b\u5b573\u78bc), \u907f\u514d\u50b3\u8f38\u904e\u7a0b\u6709\u8aa4<\/p>\n<p><!--more--><\/p>\n<pre lang=\"php\" line=\"1\">\r\nNotice: c*hr \u9700\u53bb\u9664\u5176\u4e2d\u7684 * \u865f\r\n<?php\r\n$source_str=\"BOSADM;ERP\";\r\necho \"Soruce String = $source_str\" . \"<br>\";\r\n$private_key=\"x20110301\";\r\necho \"private_key = $private_key\" . \"<br>\";\r\n$source_str_en=myEncrypt($source_str,$private_key);\r\necho \"Source string (encode) = $source_str_en\" . \"<br>\";\r\n$source_str_en_asc = to_asc($source_str_en);\r\necho \"Public Key = Source string (encode) to asc = \". $source_str_en_asc . '<br>';\r\necho \"Public Key decode (asc to c*hr) = \".to_c*hr($source_str_en_asc ) . '<br>';\r\n$source_str_de=myDecrypt(to_c*hr($source_str_en_asc ),$private_key);\r\necho \"Final decoce = $source_str_de\" . \"<br>\"; \r\n\r\n\/\/\u52a0\u5bc6\u51fd\u6578\r\nfunction myEncrypt($string, $key)\r\n{\r\n\tfor($i=0; $i<STRLEN($string);  $i++)\r\n\t{\r\n\t\tfor($j=0; $j < STRLEN($key);  $j++)\r\n\t\t{\r\n\t\t\t$string[$i] = $string[$i]^$key[$j];\r\n\t\t}\r\n\t}\r\n\treturn $string;\r\n} \r\n\r\n\/\/\u89e3\u5bc6\u51fd\u6578\r\nfunction myDecrypt($string, $key)\r\n{\r\n\tfor($i=0; $i<STRLEN($string); $i++)\r\n\t{\r\n\t\tfor($j=0; $j<STRLEN($key);  $j++)\r\n\t\t{\r\n\t\t\t$string[$i] = $key[$j]^$string[$i];\r\n\t\t}\r\n\t}\r\n\treturn $string;\r\n}\r\n\r\n\/\/\u8f49 ascii\r\nfunction to_asc($string)\r\n{\r\n\t$temp = '';\r\n\t$sub = '';\r\n\tfor($i=0; $i<STRLEN($string); $i++)\r\n\t{\r\n\t\t$sub = '000'.ord($string[$i]);\r\n\t\t$temp .= substr($sub,strlen($sub)-3,3);\r\n\t}\r\n\treturn $temp;\r\n}\r\n\r\n\/\/\u9084\u539f ascii\r\nfunction to_c*hr($string)\r\n{\r\n\t$temp = '';\r\n\tfor($i=0; $i<STRLEN($string)\/3; $i++)\r\n\t{\r\n\t\t$temp .= c*hr(substr($string,$i*3,3));\r\n\t}\r\n\treturn $temp;\r\n}\r\n?>\r\n<\/pre>\n<p>\u57f7\u884c\u7d50\u679c:<br \/>\nSoruce String = BOSADM;ERP<br \/>\nprivate_key = x20110301<br \/>\nSource string (encode) = :7+9<5C=*(\nPublic Key = Source string (encode) to asc = 058055043057060053067061042040\nPublic Key decode (asc to c*hr) = :7+9<5C=*(\nFinal decoce = BOSADM;ERP\t\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>XOR \u70ba\u52a0\u89e3\u5bc6\u7684\u4e00\u7a2e\u4f5c\u6cd5 \u4ee5\u4e0b\u7bc4\u4f8b\u70ba\u7528 php \u5be6\u4f5c\u7684\u7bc4\u4f8b: (Notice: \u70ba\u4e86\u7db2\u8def\u50b3\u8f38, \u7279\u5225\u5c07\u7de8\u78bc\u5f8c &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[56],"class_list":["post-513","post","type-post","status-publish","format-standard","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts\/513","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=513"}],"version-history":[{"count":0,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=\/wp\/v2\/posts\/513\/revisions"}],"wp:attachment":[{"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=513"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=513"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/j178.mtgbb.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=513"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}