{"id":3282,"date":"2025-04-10T19:13:34","date_gmt":"2025-04-10T10:13:34","guid":{"rendered":"https:\/\/h4ck.kr\/?p=3282"},"modified":"2025-04-10T19:13:55","modified_gmt":"2025-04-10T10:13:55","slug":"coin1","status":"publish","type":"post","link":"https:\/\/h4ck.kr\/?p=3282","title":{"rendered":"coin1"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Description (\ubc88\uc5ed\ubcf8)<\/h1>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">        ---------------------------------------------------\n        -              \uac8c\uc784\uc744 \ud574\ubcfc\uae4c\uc694?              -\n        ---------------------------------------------------\n\n        \ub2f9\uc2e0\uc740 \uc190\uc5d0 \uba87 \uac1c\uc758 \uae08\ud654\ub97c \uc950\uace0 \uc788\uc2b5\ub2c8\ub2e4\n        \ud558\uc9c0\ub9cc \uadf8\uc911 \ud558\ub098\ub294 \uc704\uc870 \ub3d9\uc804\uc785\ub2c8\ub2e4\n        \uc704\uc870 \ub3d9\uc804\uc740 \uc9c4\uc9dc \ub3d9\uc804\uacfc \ub611\uac19\uc774 \ubcf4\uc774\uc9c0\ub9cc\n        \ubb34\uac8c\uac00 \ub2e4\ub985\ub2c8\ub2e4\n        \uc9c4\uc9dc \ub3d9\uc804\uc740 10\uc758 \ubb34\uac8c\ub97c \uac00\uc9c0\uba70, \uc704\uc870 \ub3d9\uc804\uc740 9\uc758 \ubb34\uac8c\ub97c \uac00\uc9d1\ub2c8\ub2e4\n        \uc800\uc6b8\uc744 \uc0ac\uc6a9\ud574 \uc704\uc870 \ub3d9\uc804\uc744 \ucc3e\uc544\uc8fc\uc138\uc694\n        \ub9cc\uc57d 100\uac1c\uc758 \uc704\uc870 \ub3d9\uc804\uc744 \ucc3e\uc73c\uba74 \ubcf4\uc0c1\uc744 \ubc1b\uac8c \ub429\ub2c8\ub2e4 :)\n        \ucc38\uace0\ub85c, \uc2dc\uac04\uc740 60\ucd08\uc785\ub2c8\ub2e4.\n\n        - \ud50c\ub808\uc774 \ubc29\ubc95 -\n        1. \ub3d9\uc804\uc758 \uac1c\uc218(N)\uc640 \uc2dc\ub3c4 \ud69f\uc218(C)\uac00 \uc8fc\uc5b4\uc9d1\ub2c8\ub2e4\n        2. \uc800\uc6b8\uc5d0 \uc62c\ub9b4 \ub3d9\uc804\uc758 \uc778\ub371\uc2a4 \ubc88\ud638\ub97c \uc9c0\uc815\ud569\ub2c8\ub2e4\n        3. \ubb34\uac8c \uc815\ubcf4\ub97c \ubc1b\uc2b5\ub2c8\ub2e4\n        4. 2~3\ubc88 \uacfc\uc815\uc744 C\ubc88 \ubc18\ubcf5\ud55c \ub4a4 \uc815\ub2f5\uc744 \uc81c\uc2dc\ud569\ub2c8\ub2e4\n\n        - \uc608\uc2dc -\n        [\uc11c\ubc84] N=4 C=2        # 4\uac1c\uc758 \ub3d9\uc804 \uc911 \uc704\uc870 \ub3d9\uc804\uc744 2\ubc88\uc758 \uc2dc\ub3c4\ub85c \ucc3e\uae30\n        [\ud074\ub77c\uc774\uc5b8\ud2b8] 0 1     # \uccab \ubc88\uc9f8\uc640 \ub450 \ubc88\uc9f8 \ub3d9\uc804 \uc800\uc6b8\uc5d0 \uc62c\ub9ac\uae30\n        [\uc11c\ubc84] 20             # \uc800\uc6b8 \uacb0\uacfc: 20\n        [\ud074\ub77c\uc774\uc5b8\ud2b8] 3        # \ub124 \ubc88\uc9f8 \ub3d9\uc804 \uc800\uc6b8\uc5d0 \uc62c\ub9ac\uae30\n        [\uc11c\ubc84] 10             # \uc800\uc6b8 \uacb0\uacfc: 10\n        [\ud074\ub77c\uc774\uc5b8\ud2b8] 2        # \uc704\uc870 \ub3d9\uc804\uc740 \uc138 \ubc88\uc9f8!\n        [\uc11c\ubc84] \uc815\ub2f5!\n\n        - \uc900\ube44\ub418\uc168\ub098\uc694? 3\ucd08 \ud6c4 \uc2dc\uc791\ud569\ub2c8\ub2e4... -\n<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">solve.py<\/h1>\n\n\n\n<p>\ucd9c\ucc98:<\/p>\n\n\n\n<p><a href=\"https:\/\/code-angie.tistory.com\/3\">https:\/\/code-angie.tistory.com\/3<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\uc2dc\uac04\ubcf5\uc7a1\ub3c4: O(logN)<\/li>\n\n\n\n<li>\ubc18\ubcf5\ubb38\uacfc\u00a0\uc7ac\uadc0\u00a0\ub450 \uac00\uc9c0 \ubc29\ubc95\uc744 \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4. <strong>(\uc5ec\uae30\uc11c\ub294 \ubc18\ubcf5\ubb38\uc744 \uc0ac\uc6a9\ud568)<\/strong><\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\uc790\ub8cc\ub97c \uc624\ub984\ucc28\uc21c\uc73c\ub85c \uc815\ub82c\ud55c\ub2e4.<\/li>\n\n\n\n<li>\uc790\ub8cc\uc758 \uc911\uac04\uac12(mid)\uc774 \ucc3e\uace0\uc790 \ud558\ub294 \uac12(target)\uc778\uc9c0 \ube44\uad50\ud55c\ub2e4.<\/li>\n\n\n\n<li>mid \uac12\uc774 target\uacfc \ub2e4\ub974\ub2e4\uba74 \ub300\uc18c\uad00\uacc4\ub97c \ube44\uad50\ud558\uc5ec \ud0d0\uc0c9 \ubc94\uc704\ub97c \uc881\ud788\uace0, target\uacfc mid \uac12\uc774 \uac19\uc744 \ub54c\uae4c\uc9c0 \uc544\ub798 \uc870\uac74\uc5d0 \ub530\ub77c 2\ubc88\uacfc 3\ubc88\uc744 \ubc18\ubcf5\ud55c\ub2e4.<\/li>\n<\/ol>\n\n\n\n<p>\u24d0 target\uc774 middle \uac12 \ubcf4\ub2e4 \uc791\uc73c\uba74 end\ub97c middle \uc67c\ucabd \uac12\uc73c\ub85c \ubc14\uafd4\uc900\ub2e4. (\uc808\ubc18\uc758 \uc67c\ucabd \ud0d0\uc0c9)<\/p>\n\n\n\n<p>\u24d1 target\uc774 middle \uac12 \ubcf4\ub2e4 \ud06c\uba74 start\ub97c middle \uc624\ub978\ucabd \uac12\uc73c\ub85c \ubc14\uafd4\uc900\ub2e4. (\uc808\ubc18\uc758 \uc624\ub978\ucabd \ud0d0\uc0c9)<\/p>\n\n\n\n<p>\uc704 \ubc29\ubc95\ub300\ub85c \uc774\uc9c4\ud0d0\uc0c9 \uc54c\uace0\ub9ac\uc998\uc744 \ud1b5\ud574 \uac00\uc9dc \ucf54\uc778\uc774 \uc5b4\ub290 \uc778\ub371\uc2a4\uc5d0 \uc788\ub294\uc9c0 \ud30c\uc545\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<p><code>low<\/code>~<code>mid<\/code> \uae4c\uc9c0 \ud569\uc758 \ubb34\uac8c\ub97c 10\uc73c\ub85c \ub098\ub234\uc744 \ub54c, \ub098\uba38\uc9c0\uac00 9\uba74 \uac00\uc9dc \ucf54\uc778\uc774 \ud3ec\ud568\ub418\uc788\ub294\uac70\ub2e4.<\/p>\n\n\n\n<p>\uac00\uc9dc\ucf54\uc778\uc774 \ud3ec\ud568\ub420 \uacbd\uc6b0, <code>high<\/code>\ub97c <code>middle<\/code>\ub85c \uc815\ud558\uace0 \ud3ec\ud568\ub418\uc9c0 \uc54a\uc744 \uacbd\uc6b0, <code>low<\/code>\ub97c <code>middle+1<\/code> \ub85c \uc815\ud558\uc5ec\uc11c \uacc4\uc18d \ubc18\ubcf5\ubb38\uc744 \ud1b5\ud574 \ubc94\uc704\ub97c \uc881\ud600\ub098\uac00\uba74 \uac00\uc9dc \ucf54\uc778\uc774 \uc5b4\ub290 \uc778\ub371\uc2a4\uc5d0 \uc788\ub294\uc9c0 \uc54c\uc544\ub0bc \uc218 \uc788\uc5c8\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from pwn import *\n# context.log_level = 'debug'\ncontext(arch='amd64', os='linux')\nwarnings.filterwarnings('ignore')\n\np = remote(\"0.0.0.0\", 9007)\n\np.recvuntil(b\"        - Ready? starting in 3 sec... -\")\np.recvline()\np.recvline()\n\ntryCount = 0\n\nwhile True:\n    result = p.recvline()\n\n    # print(f\"result: {result}, tryCount: {tryCount}\")\n    print(f\"tryCount: {tryCount}\")\n\n    n = result.split(b\"=\")[1].split(b\" \")[0].decode('utf-8')\n    n = int(n, 10)\n\n    c = result.split(b\"=\")[2].split(b\"\\n\")[0].decode('utf-8')\n    c = int(c, 10)\n\n    print(f\"n: {n}, c: {c}\")\n\n    low = 0\n    high = n - 1\n    for i in range(c+1):\n        middle = int((low + high) \/ 2)\n        # print(f\"middle: {middle}\")\n\n        payload = \"\"\n        for j in range(low, middle + 1):\n            payload = payload + str(j) + \" \"\n        p.sendline(payload)\n        result = p.recvline()\n        if b'Correct' in result:\n            break\n        result = int(result.split(b\"\\n\")[0])\n        # print(f\"result: {result}\")\n\n        if result % 10 == 9:\n            high = middle\n        else:\n            low = middle + 1\n    tryCount += 1\n    if tryCount >= 100:\n        break \n\np.interactive()<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">Result<\/h1>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">coin1@ubuntu:\/tmp\/w4_coin1$ python3 solve.py\n[+] Opening connection to 0.0.0.0 on port 9007: Done\ntryCount: 0\nn: 205, c: 8\ntryCount: 1\nn: 480, c: 9\ntryCount: 2\nn: 423, c: 9\ntryCount: 3\nn: 850, c: 10\ntryCount: 4\nn: 580, c: 10\ntryCount: 5\nn: 687, c: 10\ntryCount: 6\nn: 154, c: 8\ntryCount: 7\nn: 102, c: 7\ntryCount: 8\nn: 299, c: 9\ntryCount: 9\nn: 195, c: 8\ntryCount: 10\nn: 67, c: 7\ntryCount: 11\nn: 555, c: 10\ntryCount: 12\nn: 361, c: 9\ntryCount: 13\nn: 247, c: 8\ntryCount: 14\nn: 112, c: 7\ntryCount: 15\nn: 826, c: 10\ntryCount: 16\nn: 973, c: 10\ntryCount: 17\nn: 482, c: 9\ntryCount: 18\nn: 835, c: 10\ntryCount: 19\nn: 424, c: 9\ntryCount: 20\nn: 358, c: 9\ntryCount: 21\nn: 87, c: 7\ntryCount: 22\nn: 77, c: 7\ntryCount: 23\nn: 623, c: 10\ntryCount: 24\nn: 96, c: 7\ntryCount: 25\nn: 131, c: 8\ntryCount: 26\nn: 937, c: 10\ntryCount: 27\nn: 914, c: 10\ntryCount: 28\nn: 843, c: 10\ntryCount: 29\nn: 640, c: 10\ntryCount: 30\nn: 869, c: 10\ntryCount: 31\nn: 422, c: 9\ntryCount: 32\nn: 727, c: 10\ntryCount: 33\nn: 929, c: 10\ntryCount: 34\nn: 865, c: 10\ntryCount: 35\nn: 748, c: 10\ntryCount: 36\nn: 709, c: 10\ntryCount: 37\nn: 491, c: 9\ntryCount: 38\nn: 146, c: 8\ntryCount: 39\nn: 708, c: 10\ntryCount: 40\nn: 344, c: 9\ntryCount: 41\nn: 628, c: 10\ntryCount: 42\nn: 882, c: 10\ntryCount: 43\nn: 302, c: 9\ntryCount: 44\nn: 61, c: 6\ntryCount: 45\nn: 504, c: 9\ntryCount: 46\nn: 144, c: 8\ntryCount: 47\nn: 724, c: 10\ntryCount: 48\nn: 603, c: 10\ntryCount: 49\nn: 465, c: 9\ntryCount: 50\nn: 386, c: 9\ntryCount: 51\nn: 362, c: 9\ntryCount: 52\nn: 680, c: 10\ntryCount: 53\nn: 368, c: 9\ntryCount: 54\nn: 766, c: 10\ntryCount: 55\nn: 304, c: 9\ntryCount: 56\nn: 487, c: 9\ntryCount: 57\nn: 263, c: 9\ntryCount: 58\nn: 9, c: 4\ntryCount: 59\nn: 433, c: 9\ntryCount: 60\nn: 698, c: 10\ntryCount: 61\nn: 979, c: 10\ntryCount: 62\nn: 77, c: 7\ntryCount: 63\nn: 426, c: 9\ntryCount: 64\nn: 936, c: 10\ntryCount: 65\nn: 347, c: 9\ntryCount: 66\nn: 164, c: 8\ntryCount: 67\nn: 349, c: 9\ntryCount: 68\nn: 767, c: 10\ntryCount: 69\nn: 204, c: 8\ntryCount: 70\nn: 897, c: 10\ntryCount: 71\nn: 886, c: 10\ntryCount: 72\nn: 277, c: 9\ntryCount: 73\nn: 464, c: 9\ntryCount: 74\nn: 380, c: 9\ntryCount: 75\nn: 253, c: 8\ntryCount: 76\nn: 354, c: 9\ntryCount: 77\nn: 645, c: 10\ntryCount: 78\nn: 259, c: 9\ntryCount: 79\nn: 980, c: 10\ntryCount: 80\nn: 620, c: 10\ntryCount: 81\nn: 465, c: 9\ntryCount: 82\nn: 207, c: 8\ntryCount: 83\nn: 410, c: 9\ntryCount: 84\nn: 892, c: 10\ntryCount: 85\nn: 36, c: 6\ntryCount: 86\nn: 831, c: 10\ntryCount: 87\nn: 570, c: 10\ntryCount: 88\nn: 447, c: 9\ntryCount: 89\nn: 948, c: 10\ntryCount: 90\nn: 85, c: 7\ntryCount: 91\nn: 960, c: 10\ntryCount: 92\nn: 720, c: 10\ntryCount: 93\nn: 243, c: 8\ntryCount: 94\nn: 953, c: 10\ntryCount: 95\nn: 259, c: 9\ntryCount: 96\nn: 545, c: 10\ntryCount: 97\nn: 17, c: 5\ntryCount: 98\nn: 917, c: 10\ntryCount: 99\nn: 889, c: 10\n[*] Switching to interactive mode\nCongrats! get your flag\nb1naRy_S34rch1Ng_1s_3asy_p3asy\n$ \n[*] Interrupted\n[*] Closed connection to 0.0.0.0 port 9007\ncoin1@ubuntu:\/tmp\/w4_coin1$ <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Description (\ubc88\uc5ed\ubcf8) solve.py \ucd9c\ucc98: https:\/\/code-angie.tistory.com\/3 \u24d0 target\uc774 middle \uac12 \ubcf4\ub2e4 \uc791\uc73c\uba74 end\ub97c middle \uc67c\ucabd \uac12\uc73c\ub85c \ubc14\uafd4\uc900\ub2e4. (\uc808\ubc18\uc758 \uc67c\ucabd \ud0d0\uc0c9) \u24d1 target\uc774 middle \uac12 \ubcf4\ub2e4 \ud06c\uba74 start\ub97c middle \uc624\ub978\ucabd \uac12\uc73c\ub85c \ubc14\uafd4\uc900\ub2e4. (\uc808\ubc18\uc758 \uc624\ub978\ucabd \ud0d0\uc0c9) \uc704 \ubc29\ubc95\ub300\ub85c \uc774\uc9c4\ud0d0\uc0c9 \uc54c\uace0\ub9ac\uc998\uc744 \ud1b5\ud574 \uac00\uc9dc \ucf54\uc778\uc774 \uc5b4\ub290 \uc778\ub371\uc2a4\uc5d0 \uc788\ub294\uc9c0 \ud30c\uc545\ud560 \uc218 \uc788\ub2e4. low~mid \uae4c\uc9c0 \ud569\uc758 \ubb34\uac8c\ub97c 10\uc73c\ub85c \ub098\ub234\uc744 \ub54c, \ub098\uba38\uc9c0\uac00 9\uba74&hellip;&nbsp;<a href=\"https:\/\/h4ck.kr\/?p=3282\" rel=\"bookmark\">\ub354 \ubcf4\uae30 &raquo;<span class=\"screen-reader-text\">coin1<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[4],"tags":[],"class_list":["post-3282","post","type-post","status-publish","format-standard","hentry","category-pwnable-kr"],"_links":{"self":[{"href":"https:\/\/h4ck.kr\/index.php?rest_route=\/wp\/v2\/posts\/3282","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/h4ck.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/h4ck.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/h4ck.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/h4ck.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3282"}],"version-history":[{"count":1,"href":"https:\/\/h4ck.kr\/index.php?rest_route=\/wp\/v2\/posts\/3282\/revisions"}],"predecessor-version":[{"id":3283,"href":"https:\/\/h4ck.kr\/index.php?rest_route=\/wp\/v2\/posts\/3282\/revisions\/3283"}],"wp:attachment":[{"href":"https:\/\/h4ck.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/h4ck.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/h4ck.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}