{"id":460,"date":"2024-10-21T02:12:49","date_gmt":"2024-10-20T18:12:49","guid":{"rendered":"https:\/\/jotaku.cn\/?p=460"},"modified":"2026-01-23T19:58:24","modified_gmt":"2026-01-23T11:58:24","slug":"%e5%8d%8e%e4%b8%ba%e6%9d%af%e7%ac%ac%e4%b8%89%e5%b1%8a%e4%b8%ad%e5%9b%bd%e7%a0%94%e7%a9%b6%e7%94%9f%e5%88%9b%e6%96%b0%e5%a4%a7%e8%b5%9bcrypto-wp-%e5%89%8d%e4%b8%a4%e9%a2%98%e5%85%a8%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/jotaku.cn\/index.php\/2024\/10\/21\/%e5%8d%8e%e4%b8%ba%e6%9d%af%e7%ac%ac%e4%b8%89%e5%b1%8a%e4%b8%ad%e5%9b%bd%e7%a0%94%e7%a9%b6%e7%94%9f%e5%88%9b%e6%96%b0%e5%a4%a7%e8%b5%9bcrypto-wp-%e5%89%8d%e4%b8%a4%e9%a2%98%e5%85%a8%e8%a7%a3%e6%9e%90\/","title":{"rendered":"2024\u534e\u4e3a\u676f \u7b2c\u4e09\u5c4a\u4e2d\u56fd\u7814\u7a76\u751f\u521b\u65b0\u5927\u8d5bCrypto WP \u524d\u4e24\u9898\u5168\u89e3\u6790"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u56db\u9053\u9898\u76ee\uff0c\u4e09\u9053RSA\u3002\u6700\u540e\u4e00\u9053\u66f4\u50cf\u662f\u7b97\u6cd5\u9898\u76ee\uff0c\u4e0d\u61c2\u7b97\u6cd5\u3002<\/p>\n\n\n\n<p>\u6211\u53d1\u73b0\uff0c\u8fd9\u4e09\u9053\u9898\u76ee\u90fd\u5728RSA\u7684\u5e95\u5c42\u6570\u5b66\u903b\u8f91\u4e0a\u505a\u4e86\u5f88\u6df1\u7684\u529f\u592b\uff0c\u53ef\u4ee5\u770b\u51fa\u51fa\u9898\u4eba\u76f8\u5f53\u6709\u6c34\u5e73\u3002\u7b2c\u4e09\u9898\u7814\u7a76\u4e86\u5f88\u957f\u65f6\u95f4\uff0c\u6574\u6574\u4e00\u4e2a\u4e0b\u5348\u52a0\u665a\u4e0a\u90fd\u5728\u548c\u8fd9\u9053\u9898\u6b7b\u78d5\uff0c\u6700\u540e\u8fd8\u662f\u803b\u8fb1\u653e\u5f03\uff0c\u4ee5\u540e\u6211\u80af\u5b9a\u80fd\u505a\u51fa\u6765\u3002<\/p>\n\n\n\n<p>\u80cc\u8d1f\u7740\u667a\u6167\u4e09\u89d2\u7684\u529b\u91cf\uff0c\u80dc\u5229\u662f\u5fc5\u7136\u7684\uff01\uff01\uff01<\/p>\n<\/blockquote>\n\n\n\n<h1 class=\"wp-block-heading\">insecure_padding<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Task<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>from Crypto.Util.number import *\nfrom secret import flag\n\nassert flag&#91;:7]==b'DASCTF{' and flag&#91;-1:]==b'}'\nflag = flag&#91;7:-1]\nassert len(flag) == 20\n\ndef my_rsa_padding(m):\n    e = 3\n    p = getPrime(1024)\n    q = getPrime(512)\n    n = p*q\n    pad = long_to_bytes(777*p+666)\n    m = bytes_to_long(m+pad)\n    assert m &lt; n\n    c = pow(m, e, n)\n    return c, e, n, len(pad)\n\nprint(my_rsa_padding(flag))\n\"\"\"\n(1193333119181381225632504634109476125461718042032463066180160159530821008151288619914035008577444580123023483451618973104785206841878926362053767758825420307104536873166791566346076985369125399199847240472385775854381103486198612767122009780041785220241663307760491699892303259600093817957324293717178123893664313547870460181936283477289029428950611459484805364390503487619676794166358047636359524103138509752217552291498141048509236471615548177017684230320627457, 3, 1345974903151028106176188777499919289689885052993818155551239513162986365479059645712347472719763678799888312063629534224676532524320490059299999431455806985776161385636341889882617880557005343019148419971407438285456200388681742721058826527478752200546957229924712840178042652788689761602760552457535667154424045780264689394678280189407534443469304768432295723527834457536647823320807747766083091825227699222804959851169910812454526260545186908048603618547346519, 130)\n\"\"\"\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Think<\/h2>\n\n\n\n<p>\u5173\u4e8e\u586b\u5145\u95ee\u9898\uff0c\u6211\u4eec\u9996\u5148\u8981\u4e86\u89e3\u586b\u5145\u4e4b\u540e\u7684flag\u662f\u4ec0\u4e48\u6837\u5b50\u7684\u3002\u6240\u4ee5\u9996\u5148\u8bb2\u4e00\u4e0b\u5173\u4e8e\u8fd9\u4e2a\u7684\u89c4\u5219\uff0c\u91cd\u70b9\u662f\u8fd9\u4e24\u884c\u4ee3\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pad = long_to_bytes(777*p+666)\nm = bytes_to_long(m+pad)<\/code><\/pre>\n\n\n\n<p>\u586b\u5145\u7684\u6570\u5b57\u662f\u5c06777*p+666\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u62fc\u63a5\u5230m\u540e\u9762\uff0c\u518d\u5c06\u62fc\u63a5\u540e\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u957f\u6574\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = 'a'\nb = 'b'\nprint(a+b)\n#ab<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u518d\u5177\u4f53\u8bb2\u4e00\u4e0bbytes_to_long\u662f\u5982\u4f55\u5de5\u4f5c\u7684\u3002<\/p>\n\n\n\n<p>bytes_to_long \u662f\u4e00\u4e2a\u628a\u5b57\u8282\u5e8f\u5217\u8f6c\u6362\u4e3a\u4e00\u4e2a\u957f\u6574\u6570\u7684\u51fd\u6570\u3002\u5b83\u4f1a\u628a\u6574\u4e2a\u5b57\u8282\u5e8f\u5217\u89c6\u4e3a\u4e00\u4e2a\u5927\u7aef\u7684\u6574\u6570\u8fdb\u884c\u89e3\u91ca\u3002\u6bd4\u5982\u5355\u72ec\u5bf9a\u8fdb\u884cbytes_to_long\u662f97\uff0c\u5355\u72ec\u5bf9b\u8fdb\u884cbytes_to_long\u662f98\u3002\u4f46\u662f\"ab\"\u5c31\u662f24930\u3002\u5177\u8c61\u6765\u770b\u5c31\u662f\u5c06\"a\"\u548c\"b\"\u7684\u4e8c\u8fdb\u5236\/\u5341\u516d\u8fdb\u5236\u524d\u540e\u62fc\u63a5\uff0c\u7136\u540e\u518d\u8f6c\u6362\u6210\u5341\u8fdb\u5236\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u3002<\/p>\n\n\n\n<p>\u6216\u8005\u6362\u4e00\u79cd\u65b9\u5f0f\u89e3\u91ca\u3002ab\u5728\u8f93\u5165\u7684\u65f6\u5019\uff0ca\u6bd4b\u9ad8\u4e00\u4e2a\u5b57\u8282\u4f4d\uff0c\u800c\u4e00\u4e2a\u5b57\u8282\u4f4d\u67098\u4e2a\u6bd4\u7279\u4f4d\u30022^8=256\u300297(a)*256 + 98(b)=24930.<\/p>\n\n\n\n<p>\u90a3\u4e48'abc'\u8f6c\u6362\u6210\u957f\u6574\u6570\u662f\u4ec0\u4e48\u6837\u7684\u5462\uff1f<\/p>\n\n\n\n<p>\u6309\u7167\u4e0a\u9762\u7684\u601d\u8def\uff0c\u662f97*2^16 + 98*2^8 + 99\uff0c\u7b54\u6848\u662f6382179\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u6362\u4e2a\u601d\u8def\u5462\uff1f\u76f4\u63a5\u5c0624980*2^8+99\uff0c\u7b54\u6848\u4e5f\u662f6382179\u3002<\/p>\n\n\n\n<p>a\u5728'ab'\u4e2d\u6bd4b\u9ad8\u4e00\u4f4d\uff0cab\u5728'abc'\u4e2d\u6bd4abc\u9ad8\u4e00\u4f4d\uff0ca\u5728'abc'\u4e2d\u6bd4bc\u9ad8\u4e24\u4f4d\u3002\u6240\u4ee5\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u8fd9\u6837\u4e00\u4e2a\u89c4\u5f8b\uff0c\u4e00\u4e2a\u5b57\u7b26\u4e32\u6bcf\u5f80\u524d\u8fdb\u4e00\u4f4d\uff0c\u5b83\u7684\u957f\u6574\u6570\u5c31\u4e58\u4ee52^8\uff0c\u8fdb\u4e24\u4f4d\u5c31\u4e58\u4ee52^16\u3002\u5c31\u662f\u8fd9\u6837\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u56de\u5230\u6211\u4eec\u7684\u9898\u76ee\uff0cm = bytes_to_long(m+pad)\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u7684m\u53ef\u4ee5\u770b\u4f5cbytes_to_long(m*2^8n) + bytes_to_long(pad)\u3002n\u7b49\u4e8epad\u7684\u4f4d\u6570 \u3002<\/p>\n\n\n\n<p>pad\u7684\u4f4d\u6570\u5728\u9898\u76ee\u6700\u540e\u7ed9\u6211\u4eec\u4e86\uff0c\u662f130\u3002130*8=1040\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u7684m\u5c31\u53ef\u4ee5\u6784\u9020\u4e3abytes_to_long(m*2^1040 + pad\uff09<\/p>\n\n\n\n<p>\u90a3\u4e48\u53ef\u5f97C\u2261(m\u00d72^1040+777p+666)^3 mod n\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684\u5316\u7b80\uff0cC\u2261(m\u00d72^1040+666)^3 mod p\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u4f60\u4eec\u6709\u6ca1\u6709\u542c\u8bf4\u8fc7coppersmith\u627e\u5c0f\u6839\uff1f<\/p>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u7528coppersmith\u627e\u51fa\u6211\u4eec\u7684\u5c0f\u6839m\u3002<\/p>\n\n\n\n<p>copper\uff0c\u6c38\u8fdc\u7684\u795e\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Exp<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>from sage.all import *\nfrom Crypto.Util.number import *\n\nc = 1193333119181381225632504634109476125461718042032463066180160159530821008151288619914035008577444580123023483451618973104785206841878926362053767758825420307104536873166791566346076985369125399199847240472385775854381103486198612767122009780041785220241663307760491699892303259600093817957324293717178123893664313547870460181936283477289029428950611459484805364390503487619676794166358047636359524103138509752217552291498141048509236471615548177017684230320627457\ne = 3\nn =  1345974903151028106176188777499919289689885052993818155551239513162986365479059645712347472719763678799888312063629534224676532524320490059299999431455806985776161385636341889882617880557005343019148419971407438285456200388681742721058826527478752200546957229924712840178042652788689761602760552457535667154424045780264689394678280189407534443469304768432295723527834457536647823320807747766083091825227699222804959851169910812454526260545186908048603618547346519\nlenpad = 130\nR.&lt;x> = PolynomialRing(Zmod(n))\nf = (x * 2**1024 + 666)**3 - c\nf = f.monic()\nm = f.small_roots(X=2**165,beta=0.66,epsilon=0.03)&#91;0]\nprint(long_to_bytes(int(m)))\n#b'P@dding_1s_important'\n#\u7136\u540e\u5305\u8fdbDASctf{}\u91cc\u5c31\u53ef\u4ee5\u4e86<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">EZ_RSA_5<\/h1>\n\n\n\n<p>\u6b64trick\u5728hitcon2019\u4e2d\u4ea6\u6709\u8bb0\u8f7d\uff0c\u751a\u81f3\u96be\u5ea6\u8fd8\u9ad8\u4e86\u4e00\u70b9\uff1f<\/p>\n\n\n\n<p>\u611f\u53f9\u5916\u56fd\u7684CTF\u8fd8\u662f\u6bd4\u56fd\u5185\u9886\u5148\u554a\uff0chitcon\u4e94\u5e74\u524d\u7684\u9898\u4e86\u90fd\uff0c\u4e94\u5e74\u524d\u6211\u8fd8\u521d\u4e09\u5462<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/pcw109550\/write-up\/tree\/master\/2019\/HITCON\/Lost_Modulus_Again\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/github.com\/pcw109550\/write-up\/tree\/master\/2019\/HITCON\/Lost_Modulus_Again<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Task<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>from Crypto.Util.number import *\nimport gmpy2\nfrom secret import flag\n\nm=bytes_to_long(flag)\n\np=getPrime(512)\nq=getPrime(512)\ne=65537\nn=p*q\n\nphi =(p-1)*(q-1)\np1 = gmpy2.invert(p,q)\nq1 = gmpy2.invert(q,p)\n\nc = pow(m,e,n)\nP = pow(m,p,n)\nQ = pow(m,q,n)\nK = P*Q\n\nphi_K=(P-1)*(Q-1)\nd=inverse(e,phi_K)\ndp=d%(P-1)\n\nprint(\"p1 =\",p1)\nprint(\"q1 =\",q1)\nprint(\"phi =\",phi)\nprint('K = ',K)\nprint('dp = ',dp)\n\n'''\n\np1 = 2636020992576559969055483957060200941734026828135579110378070592732862908176025649071069827089999996350015210043636523971348821850565913816154887832272305\nq1 = 7886513101716991094728039196608717849158915101115291363845210343608904418304571443491051842715241903123031976527174063528298034452215971449949398656913945\nphi = 115505961171763309547793530782914001823768056515083869218337105172209622283311582473506324170565971054492347897941697574972266679462737991988159654350224823122310342866537098903019067348499259894857405865405379172014292034138593409888061494667098647947191077373457924105640280156013690526621147715122416478264\nK =  3995906172915513953882445609459153360257793100017419734812726991957587919349807133880917342081892953635338598486012480314014321088548439223094566668968735207492741920107799674089668131177188073985125603237341660194741854181484934968528811686828555591685803851909027192343245722679639249600176791158349393704697742640442010893811830528349203606514981272974154582682489532205008927740716725904614810707240205595586894383039181983075907373556864396176123489201513001026708388504250801785422323131912494763394371589512367935031912074535458595633402462463667072692589863355712935552396330534658448628449816139943205511637\ndp =  53589538487289875479012684116246778147274714450209576105277816626983528993595125486641833027290704077932308918237978477501981907543847383655230156916578979044682282870153618849419762148348930652564442177633668690473147864322377146889467662769284463217004314651469157455678363085510100707437896627192687923547\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Think<\/h2>\n\n\n\n<p>\u8fd9\u4e00\u9898\u4e5f\u662f\u666e\u901a\u7684ezRSA\uff0c\u7136\u540ep1\u662fp\u7684\u9006\u5143\u6a21q\uff0cq1\u662fq\u7684\u9006\u5143\u6a21p\u3002C\uff0cP\uff0cQ\u662f\uff08\uff09\uff0c\u603b\u4e4b\u6709\u90a3\u4e48\u51e0\u4e2a\u53c2\u6570\u3002<\/p>\n\n\n\n<p>\u6211\u4e4b\u524d\u5199\u8fc7\u8fd9\u6837\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u5df2\u77e5N\uff0cdp\u6216\u8005dq\uff0ce\u5c31\u80fd\u5c06n\u5206\u89e3\u3002\u4f46\u90a3\u662f\u9488\u5bf9n\u7684\u4e24\u4e2a\u56e0\u6570\u662f\u7d20\u6570\u7684\u60c5\u51b5\u4e0b\u3002\u8fd9\u91cc\u7684K\u5e76\u4e0d\u80fd\u4fdd\u8bc1P\u548cQ\u90fd\u662f\u8d28\u6570\u3002\u6240\u4ee5\u6211\u4eec\u8981\u5c3d\u53ef\u80fd\u591a\u7684\u904d\u5386\u53ef\u80fd\u503c\u3002\u628a\u6240\u6709\u7684\u53ef\u80fd\u503c\u90fd\u5217\u51fa\u6765\uff0c\u4eba\u773c\u7b5b\u9009\u4e00\u4e0b\u53ef\u80fd\u7684P\u548cQ\u3002\u4f46\u662f\u80fd\u8dd1\u51fa\u6765\u7684p\u548cq\u592a\u591a\u4e86\uff0c\u6b63\u5982\u6211\u4eec\u4e0a\u9762\u6240\u8bf4\u7684\u4e0d\u80fd\u4fdd\u8bc1P\u548cQ\u90fd\u662f\u8d28\u6570\u3002\u5148\u628a\u4ee3\u7801\u8d34\u4e00\u4e0b\u5427\u3002\u6570\u5b66\u539f\u7406\u4ee5\u540e\u518d\u6c34\u4e00\u7bc7\u6587\u7ae0\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import gmpy2\n\ndef recover_all_ps(dp, e, n):\n    factors = set()\n    for a in range(2, 20000):\n        left = pow(a, e * dp, n) - a\n        p = gmpy2.gcd(left, n)\n        if p != 1 and p != n:\n            factors.add(p)\n    return factors\n\ndp = 53589538487289875479012684116246778147274714450209576105277816626983528993595125486641833027290704077932308918237978477501981907543847383655230156916578979044682282870153618849419762148348930652564442177633668690473147864322377146889467662769284463217004314651469157455678363085510100707437896627192687923547\ne = 65537\nn = 3995906172915513953882445609459153360257793100017419734812726991957587919349807133880917342081892953635338598486012480314014321088548439223094566668968735207492741920107799674089668131177188073985125603237341660194741854181484934968528811686828555591685803851909027192343245722679639249600176791158349393704697742640442010893811830528349203606514981272974154582682489532205008927740716725904614810707240205595586894383039181983075907373556864396176123489201513001026708388504250801785422323131912494763394371589512367935031912074535458595633402462463667072692589863355712935552396330534658448628449816139943205511637\n\nfactors = recover_all_ps(dp, e, n)\nfor p in factors:\n    q = n \/\/ p\n    print(\"p =\", p)\n    print(\"q =\", q)\n<\/code><\/pre>\n\n\n\n<p>\u6211\u5728a\u5c5e\u4e8e(0,2000]\u4e2d\u7206\u7834\u51fa\u4e86\u4ee5\u4e0b\u53ef\u80fd\u6027<\/p>\n\n\n\n<p>\u6682\u65f6\u65e0\u6cd5\u5728\u98de\u4e66\u6587\u6863\u5916\u5c55\u793a\u6b64\u5185\u5bb9<\/p>\n\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u8fd8\u662f\u5f88\u591a\u7684\uff0c\u518d\u5f80\u5927\u7684\u7206\u6211\u76f8\u4fe1\u8fd8\u4f1a\u66f4\u591a<\/p>\n\n\n\n<p>\u5f53\u7136\u8fd8\u6709\u53e6\u4e00\u4e2a\u529e\u6cd5\uff0c\u8fd9\u4e2a\u4e5f\u662f\u8981\u7275\u626fRSA\u7684\u52a0\u5bc6\u903b\u8f91\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u77e5\u9053\uff0c\u5728RSA\u4e2d\u6ee1\u8db3d*e \u2261 1 mod\u2009\u2009\u03d5(n)\uff08\u5728\u8fd9\u9898\u4e2d\u662f\u03d5(K)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u867d\u7136\u8fd9\u4e2a\u4e5f\u4e0d\u662frsa\uff0c\u4e0d\u8fc7\u533a\u522b\u53ea\u5728P\u548cQ\u662f\u4e0d\u662f\u7d20\u6570\uff0c\u4e0d\u5f71\u54cd\u7684<\/p>\n\n\n\n<p>K = P*Q phi_K=(P-1)*(Q-1) d=inverse(e,phi_K) dp=d%(P-1)<\/p>\n<\/blockquote>\n\n\n\n<p>\u4e5f\u5c31\u662f\u8bf4\uff0ce * d - 1 = k * \u03d5(K)\uff08k\u662f\u67d0\u4e2a\u6574\u6570<\/p>\n\n\n\n<p>\u540c\u65f6\u56e0\u4e3a\uff08P-1\uff09\u662f\u03d5(K)\u7684\u56e0\u6570\uff0c\u6240\u4ee5e * d - 1 = k * (P-1)<\/p>\n\n\n\n<p>\u540c\u65f6\uff0c\u6211\u4eec\u4e5f\u6709dp=d%(P-1)\uff0c\u90a3\u4e48\u53ef\u4ee5\u5f97\u51fad = k1 * (P\u22121) + dp<\/p>\n\n\n\n<p>\u90a3\u4e48\u6211\u4eec\u5c31\u53ef\u4ee5\u5199\u51fa\u540c\u4f59\u5f0fdp*e \u2261 1 + k\u22c5(p\u22121)<\/p>\n\n\n\n<p>\u8f6c\u5316\u4e00\u4e0b\u5c31\u662f dp*e - 1 \u2261k*(P\u22121)<\/p>\n\n\n\n<p>\u8fd9\u91cc\u9762\u6709\u56db\u4e2a\u672a\u77e5\u91cf\uff0c\u6709\u4e00\u4e2ak\u672c\u6765\u5c31\u662f\u8981\u7206\u7834\u7684\uff0c\u8fd9\u8fd8\u89e3\u4e0d\u51fa\u6765P\uff1f<\/p>\n\n\n\n<p>-------------Q.E.D<\/p>\n\n\n\n<p>\u6839\u636e\u6570\u5b66\u63a8\u5bfc\u5199\u811a\u672c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from Crypto.Util.number import *\nimport gmpy2\n\ndp = 53589538487289875479012684116246778147274714450209576105277816626983528993595125486641833027290704077932308918237978477501981907543847383655230156916578979044682282870153618849419762148348930652564442177633668690473147864322377146889467662769284463217004314651469157455678363085510100707437896627192687923547 \ne = 65537\nK = 3995906172915513953882445609459153360257793100017419734812726991957587919349807133880917342081892953635338598486012480314014321088548439223094566668968735207492741920107799674089668131177188073985125603237341660194741854181484934968528811686828555591685803851909027192343245722679639249600176791158349393704697742640442010893811830528349203606514981272974154582682489532205008927740716725904614810707240205595586894383039181983075907373556864396176123489201513001026708388504250801785422323131912494763394371589512367935031912074535458595633402462463667072692589863355712935552396330534658448628449816139943205511637\n\nfor i in range(1, e):\n    if (dp * e - 1) % i == 0:\n        P = (dp * e - 1) \/\/ i + 1      \n        if K % P == 0:\n            Q = K \/\/ P\n\n            print(\"P=\",P)\n            print(\"Q=\",Q)\n            \n\n#P=89706459192396530593549443920371512846107199328839237547229758327568121878195799315931797683572600269608687634404290962684155916188631860811034680949192525086238991914925741833782609688548028611711472171734508568556069872649373734405124829887118997365400928949792704456407061927794321219467125520582544212039\n#Q=44544241394539455087080003827042433390596610554187086515097380871947145536991877216409262767617552724165444473076549560658417398194657348107209262950353565993877966067642602951964287850776064487853037993132356275513691026700801254797314898063932907251598380047383415220014112316421578570998223070668797351683<\/code><\/pre>\n\n\n\n<p>\u90a3\u4e48\u6709\u4e86P\u548cQ\uff0c\u6211\u4eec\u8fd8\u5f97\u60f3\u529e\u6cd5\u89e3\u51fa\u6765p\u548cq\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>phi =(p-1)*(q-1) p1 = gmpy2.invert(p,q) q1 = gmpy2.invert(q,p) c = pow(m,e,n) P = pow(m,p,n) Q = pow(m,q,n)<\/p>\n<\/blockquote>\n\n\n\n<p>\u6211\u4eec\u6709phi\uff0c\u6709p1\uff0cp2\uff0c\u4e5f\u89e3\u51fa\u6765\u4e86P\u548cQ\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import sympy\nimport gmpy2\nx = 2636020992576559969055483957060200941734026828135579110378070592732862908176025649071069827089999996350015210043636523971348821850565913816154887832272305\ny = 7886513101716991094728039196608717849158915101115291363845210343608904418304571443491051842715241903123031976527174063528298034452215971449949398656913945\nphi = 115505961171763309547793530782914001823768056515083869218337105172209622283311582473506324170565971054492347897941697574972266679462737991988159654350224823122310342866537098903019067348499259894857405865405379172014292034138593409888061494667098647947191077373457924105640280156013690526621147715122416478264\n\ndef solve(a, b, c):\n    D = b ** 2 - 4 * a * c\n    # assert gmpy2.is_square(D)\n    x1 = (-b + gmpy2.isqrt(D)) \/\/ (2 * a)\n    x2 = (-b - gmpy2.isqrt(D)) \/\/ (2 * a)\n    return x1, x2\n\na = x - 1\nb = x * y - 1 + (x - 1) * (y - 1) - phi\nc = (y - 1) * (x * y - 1)\nk1, k2 = solve(a, b, c)\nif (x * y - 1) % k1 == 0:\n    k2 = (x * y - 1) \/\/ k1\nelif (x * y - 1) % k2 == 0:\n    k1, k2 = k2, (x * y - 1) \/\/ k2\nelse:\n    assert False\n\np, q = x + k2, y + k1\nprint(p)\nprint(q)\n\n#11198469463791545278619772990550048972153411253872703306559384762341904625491585546901465814421769882976230432056883880344770707467660327961608441011384163\n#10314441767710606102937195215834089659678641178199945218290612694615948834633793866983953938981209335187624023708779675532856424652499590260914133511985373<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u6709\u4e86p\u548cq\uff0c\u6b63\u5f53\u6211\u60f3\u53bb\u5199\u89e3\u9898\u811a\u672c\u7684\u65f6\u5019\u5ffd\u7136\u611f\u89c9\u5341\u5206\u6709\u4e5d\u5206\u7684\u4e0d\u5bf9\u52b2\uff01<\/p>\n\n\n\n<p>\u6211\u5bc6\u6587\u5462\uff01\u5b83\u6ca1\u6709\u7ed9\u6211\u5bc6\u6587\uff01\ud83d\ude2d<\/p>\n\n\n\n<p>\u90a3\u6211\u53ea\u597dcoppersmith\u4e86\u261d\ufe0f\ud83e\udd13<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Exp<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import gmpy2\nimport sympy\nfrom Crypto.Util.number import *\nfrom mpmath.libmp.backend import sage_utils\n\ne=65537\nK =  3995906172915513953882445609459153360257793100017419734812726991957587919349807133880917342081892953635338598486012480314014321088548439223094566668968735207492741920107799674089668131177188073985125603237341660194741854181484934968528811686828555591685803851909027192343245722679639249600176791158349393704697742640442010893811830528349203606514981272974154582682489532205008927740716725904614810707240205595586894383039181983075907373556864396176123489201513001026708388504250801785422323131912494763394371589512367935031912074535458595633402462463667072692589863355712935552396330534658448628449816139943205511637\ndp =  53589538487289875479012684116246778147274714450209576105277816626983528993595125486641833027290704077932308918237978477501981907543847383655230156916578979044682282870153618849419762148348930652564442177633668690473147864322377146889467662769284463217004314651469157455678363085510100707437896627192687923547\n\nphi_K=3995906172915513953882445609459153360257793100017419734812726991957587919349807133880917342081892953635338598486012480314014321088548439223094566668968735207492741920107799674089668131177188073985125603237341660194741854181484934968528811686828555591685803851909027192343245722679639249600176791158349393704563491939855074908131201080601789660278277463091128258620162393005493660325529049372273750256050052601812762275558341459733334059173575187257879545301966909946591430521682456999675425592588401663829861424645503090962151175185283606430962734512615168075590554358536815875975156290442548837984467548691863947916\nP=89706459192396530593549443920371512846107199328839237547229758327568121878195799315931797683572600269608687634404290962684155916188631860811034680949192525086238991914925741833782609688548028611711472171734508568556069872649373734405124829887118997365400928949792704456407061927794321219467125520582544212039\nQ=44544241394539455087080003827042433390596610554187086515097380871947145536991877216409262767617552724165444473076549560658417398194657348107209262950353565993877966067642602951964287850776064487853037993132356275513691026700801254797314898063932907251598380047383415220014112316421578570998223070668797351683\nx = 2636020992576559969055483957060200941734026828135579110378070592732862908176025649071069827089999996350015210043636523971348821850565913816154887832272305\ny = 7886513101716991094728039196608717849158915101115291363845210343608904418304571443491051842715241903123031976527174063528298034452215971449949398656913945\nphi = 115505961171763309547793530782914001823768056515083869218337105172209622283311582473506324170565971054492347897941697574972266679462737991988159654350224823122310342866537098903019067348499259894857405865405379172014292034138593409888061494667098647947191077373457924105640280156013690526621147715122416478264\n\nd=inverse(e,phi_K)\ndef solve(a, b, c):\n    D = b ** 2 - 4 * a * c\n    # assert gmpy2.is_square(D)\n    x1 = (-b + gmpy2.isqrt(D)) \/\/ (2 * a)\n    x2 = (-b - gmpy2.isqrt(D)) \/\/ (2 * a)\n    return x1, x2\n\na = x - 1\nb = x * y - 1 + (x - 1) * (y - 1) - phi\nc = (y - 1) * (x * y - 1)\nk1, k2 = solve(a, b, c)\nif (x * y - 1) % k1 == 0:\n    k2 = (x * y - 1) \/\/ k1\nelif (x * y - 1) % k2 == 0:\n    k1, k2 = k2, (x * y - 1) \/\/ k2\nelse:\n    assert False\np, q = x + k2, y + k1\nn = p * q\nPR.&lt;m&gt; = PolynomialRing(Zmod(n))\nf = m^2 - (P+Q)*m + P*Q\nx0 = f.small_roots()&#91;0]\nprint(long_to_bytes(int(x0)))\n\n#b'DASCTF{this_1s_crazy_Rsa}'<\/code><\/pre>\n\n\n\n<p>\u592aCrazy\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u5171\u56db\u9053\u9898\uff0c\u6211\u53ea\u4f1a\u524d\u4e24\u9053\u9898\u3002\u8fd8\u662f\u6280\u672f\u4e0d\u591f\u554a<\/p>\n","protected":false},"author":3,"featured_media":341,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-460","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tec"],"_links":{"self":[{"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/posts\/460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/comments?post=460"}],"version-history":[{"count":4,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/posts\/460\/revisions"}],"predecessor-version":[{"id":541,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/posts\/460\/revisions\/541"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/media\/341"}],"wp:attachment":[{"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/media?parent=460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/categories?post=460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/tags?post=460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}