{"id":507,"date":"2024-11-30T16:43:20","date_gmt":"2024-11-30T08:43:20","guid":{"rendered":"https:\/\/jotaku.cn\/?p=507"},"modified":"2024-11-30T16:44:17","modified_gmt":"2024-11-30T08:44:17","slug":"2024%e6%b1%9f%e8%8b%8f%e7%a7%bb%e5%8a%a8%e8%b5%8b%e8%83%bd%e8%b5%9bcrypto-rsa2","status":"publish","type":"post","link":"https:\/\/jotaku.cn\/index.php\/2024\/11\/30\/2024%e6%b1%9f%e8%8b%8f%e7%a7%bb%e5%8a%a8%e8%b5%8b%e8%83%bd%e8%b5%9bcrypto-rsa2\/","title":{"rendered":"2024\u6c5f\u82cf\u79fb\u52a8\u8d4b\u80fd\u8d5bCrypto RSA2"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5176\u4ed6\u7684\u9898\u76ee\u90fd\u592a\u7b80\u5355\u4e86\uff0c\u8fd9\u4e00\u9053\u9898\u867d\u7136\u4e5f\u4e0d\u96be\uff0c\u4f46\u662f\u7531\u4e8e\u975e\u9884\u671f\u89e3\u7684\u5b58\u5728\uff0c\u8fd8\u662f\u633a\u6709\u610f\u601d\u7684<\/p>\n<\/blockquote>\n\n\n\n<h1 class=\"wp-block-heading\">RSA2<\/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 getStrongPrime, bytes_to_long\nfrom gmpy2 import powmod\nfrom secret import flag\n\np = getStrongPrime(512)\nq = getStrongPrime(512)\nr = getStrongPrime(512) * p\nn = p * q * r\nt1 = 2334 + r - r \/\/ p - p\nt2 = 23334 + r - r \/\/ p - p\ntest_1 = powmod(q, t1, r)\ntest_2 = powmod(q, t2, r)\n\ne = 65537\nm = bytes_to_long(flag)\nc = powmod(m, e, n)\nprint(f\"n = {n}\")\nprint(f\"c = {c}\")\nprint(f\"e = {e}\")\nprint(f\"r = {r}\")\nprint(f\"test_1 = {test_1}\")\nprint(f\"test_2 = {test_2}\")\n\n\"\"\"\nn = 19394374939804636077298787696999145651388601917322114895642838853953381808240702298158075667836933844491914300462200498201232502597820471480278104873709079654383571733982600793391645736041575554416761411190577666894319909094358212628600451699873050386633961355953081164797613802471503835972928156332452586946123449475018268744050878129654089828539569290163248669910546474863971193248913060301042961297573273735567035638484842640891102000757796883117449143733645075205787306969545619475615329292516687937499869527048405181860848871040143454231725384444493671341489194232832604336747339981987968136805889988687471700689\nc = 3445029509586789808191705086645892423344577895037990571917352198546103689956715444033789264619614928374173476257167068005615154238272256059206608521783259242336753735756270112683064185174154799787961620809472112672118869269531775498552913966749136960082148806701372215067784028138932161876481489483873874799577724564723536348878312087744205685152618944049898188467560333943868310819003549830041266285452470975843082633880273304056420983351380067924031473031902543251747872634679470807321088893876373614041197021272507490311894156474653766409806436771639703723056721686546437267761800664890347807938625483929875463817\ne = 65537\nr = 137186922017951798551013401031704441055292816273244383207330822587665397547633114179564214318161419547692944354372913721036795205992346900855775319896575433470493561754043711065187018521093256306861110861619139917879019066158769928044089694954100132993743545321108599987390965031813714252751340253063380122781  \ntest_1 = 10484222645942880569836346075211281500874316946773201245651921797050891795748018447890023984042009352443993529052624578259137283707622203132903778636427100673857236327880267380370130055336876593685230110403102135481150897000578831309789840644914684399062683490015265131603393965109484777590220067155254662724\ntest_2 = 46456546765497070754887354077605248455173445868539256339074654174920046820647882073337928470491562197950314697051806785137505130712091646483422595416843622895712210098782991926220638941734115040651715763329324337370957581802656073016916306620765962524561139196288970336270965816673108758049003178870509619277\n\"\"\"\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Think<\/h2>\n\n\n\n<p>\u770b\u9898\u76ee<strong>\u63e3\u6d4b\u51fa\u9898\u4eba\u7684\u610f\u56fe<\/strong>\uff0c\u5bf9t1\u548ct2\u6a21\u4e00\u4e2ap\uff0c\u5f97\u51fat1 = 2333 mod p\uff0ct2 = 23333 mod p\u3002\u770b\u8fd9\u79cd\u60c5\u51b5\u5927\u80c6\u75282333\u548c23333\u66ff\u6362t1\u548ct2\u5bf9\u5176\u8fdb\u884c\u5171\u6a21\u653b\u51fb\uff0c\u53ef\u4ee5\u89e3\u51fa\u6765q\u3002\u7136\u540e\u89e3\u51fap\u5f97\u51faflag\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u8fd9\u9898\u8fd8\u6709\u4e00\u4e2a\u975e\u9884\u671f\u89e3\u3002n\/\/r = p * q\u3002r = p * q\u3002\u8d70\u4e00\u4e2agcd(n\/\/r,r)\u5c31\u80fd\u6c42\u51fa\u6765p\uff0c\u540c\u6837\u6210\u529f\u5206\u89e3\u4e86n\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Exp<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>from Crypto.Util.number import *\nfrom gmpy2 import invert\n\nn = 19394374939804636077298787696999145651388601917322114895642838853953381808240702298158075667836933844491914300462200498201232502597820471480278104873709079654383571733982600793391645736041575554416761411190577666894319909094358212628600451699873050386633961355953081164797613802471503835972928156332452586946123449475018268744050878129654089828539569290163248669910546474863971193248913060301042961297573273735567035638484842640891102000757796883117449143733645075205787306969545619475615329292516687937499869527048405181860848871040143454231725384444493671341489194232832604336747339981987968136805889988687471700689\nc = 3445029509586789808191705086645892423344577895037990571917352198546103689956715444033789264619614928374173476257167068005615154238272256059206608521783259242336753735756270112683064185174154799787961620809472112672118869269531775498552913966749136960082148806701372215067784028138932161876481489483873874799577724564723536348878312087744205685152618944049898188467560333943868310819003549830041266285452470975843082633880273304056420983351380067924031473031902543251747872634679470807321088893876373614041197021272507490311894156474653766409806436771639703723056721686546437267761800664890347807938625483929875463817\ne = 65537\nr = 137186922017951798551013401031704441055292816273244383207330822587665397547633114179564214318161419547692944354372913721036795205992346900855775319896575433470493561754043711065187018521093256306861110861619139917879019066158769928044089694954100132993743545321108599987390965031813714252751340253063380122781\ntest_1 = 10484222645942880569836346075211281500874316946773201245651921797050891795748018447890023984042009352443993529052624578259137283707622203132903778636427100673857236327880267380370130055336876593685230110403102135481150897000578831309789840644914684399062683490015265131603393965109484777590220067155254662724\ntest_2 = 46456546765497070754887354077605248455173445868539256339074654174920046820647882073337928470491562197950314697051806785137505130712091646483422595416843622895712210098782991926220638941734115040651715763329324337370957581802656073016916306620765962524561139196288970336270965816673108758049003178870509619277\n\ndef egcd(a, b):\n    if a == 0:\n        return (b, 0, 1)\n    else:\n        g, y, x = egcd(b % a, a)\n        return (g, x - (b \/\/ a) * y, y)\n\ne1 = 2333\ne2 = 23333\nc1 = test_1\nc2 = test_2\n\ng, s1, s2 = egcd(e1, e2)\n\nif g != 1:\n    raise ValueError(\"false\")\n\nc1_inv = pow(c1, s1, r) \nc2_inv = pow(c2, s2, r) \n\nq = c1_inv * c2_inv % r\np = n \/\/ (q * r)\nk = r \/\/ p\nphi = p*(p - 1) * (q - 1) * (k - 1)\nd = invert(e, phi)\nm = pow(c, d, n)\nprint(long_to_bytes(m))\n\n#------------>\u4ee5\u4e0b\u662f\u975e\u9884\u671f\u89e3\u811a\u672c&lt;-----------------\nfrom Crypto.Util.number import long_to_bytes, GCD\n\nn = 19394374939804636077298787696999145651388601917322114895642838853953381808240702298158075667836933844491914300462200498201232502597820471480278104873709079654383571733982600793391645736041575554416761411190577666894319909094358212628600451699873050386633961355953081164797613802471503835972928156332452586946123449475018268744050878129654089828539569290163248669910546474863971193248913060301042961297573273735567035638484842640891102000757796883117449143733645075205787306969545619475615329292516687937499869527048405181860848871040143454231725384444493671341489194232832604336747339981987968136805889988687471700689\nc = 3445029509586789808191705086645892423344577895037990571917352198546103689956715444033789264619614928374173476257167068005615154238272256059206608521783259242336753735756270112683064185174154799787961620809472112672118869269531775498552913966749136960082148806701372215067784028138932161876481489483873874799577724564723536348878312087744205685152618944049898188467560333943868310819003549830041266285452470975843082633880273304056420983351380067924031473031902543251747872634679470807321088893876373614041197021272507490311894156474653766409806436771639703723056721686546437267761800664890347807938625483929875463817\nr = 137186922017951798551013401031704441055292816273244383207330822587665397547633114179564214318161419547692944354372913721036795205992346900855775319896575433470493561754043711065187018521093256306861110861619139917879019066158769928044089694954100132993743545321108599987390965031813714252751340253063380122781\np = GCD(n\/\/r, r)\n#\u751a\u81f3\u8fd9\u65f6\u5019\u76f4\u63a5\u7528print(long_to_bytes(pow(c, pow(65537, -1, p-1), p)))\u5c31\u80fd\u51faflag\nq = n\/\/(r * p)\nk = r \/\/ p\nphi = p*(p - 1) * (q - 1) * (k - 1)\nd = invert(e, phi)\nm = pow(c, d, n)\nprint(long_to_bytes(m))\n\n\n<\/code><\/pre>\n\n\n\n<p>flag{469c3244-1a40-4372-9aae-bca0aa75c583}<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u5355\u9898\u76ee\uff0c\u4f46\u662f\u5b58\u5728\u975e\u9884\u671f\u89e3<\/p>\n","protected":false},"author":3,"featured_media":490,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-507","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/posts\/507","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=507"}],"version-history":[{"count":4,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/posts\/507\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/posts\/507\/revisions\/511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/media\/490"}],"wp:attachment":[{"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/media?parent=507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/categories?post=507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jotaku.cn\/index.php\/wp-json\/wp\/v2\/tags?post=507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}