提示されたサーバに接続すると、まず最初にsha256ハッシュ値の下6桁に一致する文字列の入力を求められます。これはランダムな文字列を繰り返し生成しそのsha256ハッシュ値の下6桁を比較して文字列を求めます。
それをクリアすると本題になります。与えられた大きな整数値(n)に対して、それを超えない最大の累乗数(xのy乗で表される数)を見つけて、n-x**yの値を答えるというものです。
この課題を解くPythonプログラムを下記します。
import socket
import sys
import string
import random
import hashlib
import math

###########################
def hash_test(hash):
n = 5
while True:
random_str = ''.join([random.choice(string.ascii_letters + string.digits + string.punctuation) for i in range(n)])
if hash == hashlib.sha256(random_str).hexdigest()[-6:]:
return random_str

def nroot(n, k):
    x = 2 ** int(math.ceil(math.log(n, 2)/k))
    y = ((k-1)*x + n / x ** (k-1)) / k
    while y < x:
        x = y
        y = ((k-1)*x + n / x ** (k-1)) / k
    return x

def solve(n):
    r = float('inf')
    y = 2
    while True:
        x = nroot(n, y)
        m = n - x ** y
        if r > m:
            r = m
        if x == 2:
            break
        y += 1
    return r

host = '37.139.22.174'
if len(sys.argv) > 1:
    host = sys.argv[1]
port = 11740
if len(sys.argv) > 2:
    host = int(sys.argv[2])
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((host, port))

client_file = client.makefile('b')

while True:
    s = client_file.readline().strip()
    print(s)
    if 'Submit a printable string X, such that sha256(X)[-6:]' in s:
        break

hash = s.split()[9]
a = hash_test(hash)
print(a)
client_file.write(a + "\n")
client_file.flush()

while True:
    while True:
        s = client_file.readline().strip()
        print(s)
        if s.startswith('n = '):
            break
        elif 'ASIS{' in s:
            sys.exit()
    n = int(s.split()[2])

    while True:
        s = client_file.readline().strip()
        print(s)
        if 'To win the flag, submit r :)' in s:
            break

    r = solve(n)
    print(r)
    client_file.write(str(r) + "\n")
    client_file.flush()
実行すると、うまくフラグを取得することができました。
>ccc.py
*****************************************************************************
| Welcome to the Near Neighbor Problem, only mathematicians know the flag!! |
| Your mission is to find smallest natural number r for given n, such that  |
| there exist integers x, y: n - x**y = r > 0, x > 1 and y > 1. good luck!! |
*****************************************************************************
Submit a printable string X, such that sha256(X)[-6:] = fb18dd
i1++(
Please be patient ...
It takes a few seconds to load ...
n = 42713653694583983917620633592482448293294093258667415643252682236167888288964999713885812047533602109960168082130810948514035606387087967935594322305474125977354110862303478451015550305544814896711627803736665360621081230492228907432486729823918397977491607816749292910570447379496441921865495916775310468527140030451083906354541516728225151616776547670010327038887765396600316566279294093701940815771548023557472233154394104045165112075492632295386261916504936672258184211757240396922852248405647272131238621214104903342821311907655510975811492771148217955616721879060175182912822690333624279243631263938197402278898713444374965478809525154324961291401697549189065199114170246756531312184508886269455303476883915075611954490200843557161122839278006298154207231707901194058849003875281067527059480661749386360293897767533477457119541287157895459572460126976224384416438750189871295788
To win the flag, submit r :)
4459606347895459572460126976224384416438750189871295788
Great! :) please pass the next stage :P
n = 924257951149882570317917711254673494448840369977224014381744199905788559823867115663520627473666
To win the flag, submit r :)
3623664227916706834366291295490
Great! :) please pass the next stage :P
n = 65479758012639802017637216949111190165775936308342951533429010383261508472997822758685306430423975715111257497850480690866939487548033779052220523490514490329325080907105034355378449479535504299026482146500942630540193926289616449335261298177869552294913541025074865786996895579458195472000858373211577122436897518360407589533429207756672693902458310229293285183047704068948226937369541524699815867986295192206591734728
To win the flag, submit r :)
166861975878844103
Great! :) please pass the next stage :P
n = 217767580286127017190145533588803219848286319785898002433687115334542020630900969886690141088296477253939369853296204945210719758876534662130978363080440623651560881192412296228443096503146937981533578909952628891621309547725977275218874177043267826828489126765819157664677814456120164453469156088499304205808558888507588613388971418094024635697007295411179752293456625759040682154026255906740801237720603078057762603849512862407652271059275090405605732274437010097949054986308333152879473562023994660452792100586673285019917529657242954558167519493373896387016422341395137695658959561368034439773888289999650713891464374990076436137303569130110298599113198112321996084377399816203845185168347145130320696047287365519994784995399187688665609440580895
To win the flag, submit r :)
8916891587871
Great! :) please pass the next stage :P
n = 284477657175020238466381705031890624059673697588531438615565748803397181660936153169604142697233704020337293792389094466850509988785581342482327916496783450987401360133222989546392641321734053647396552981571037168040752960602672269153138323875514116268145661695528626712731506962302694526736493218673715635157039166099513109345713963313619841316821792046713238054614031786159100854417186292494885247825323939639455587574728838157238413485822299833654446753880023610472347460605439900723468985557266609763729082722418880788208670600558583226837174354207604141787526553596859305997349949585312204722374969479693811452708735044950986335035368318090725293608603307710688150869214554988100461797667329927214643249930342991669272013622239738135130670361980031485000118982755276270302407149965513820460060374000054480175477038831701074201584241548698111938843837240054225023331609638536054564498344867098347471634432000000000000000000000000000000000000433930856920505
To win the flag, submit r :)
433930856920505
Great! :) please pass the next stage :P
n = 446812435463188228108507290517210934738976598075494463136252007658339499637332994778105048922921464416669623002960271938850251682688764630788078036374647127041150118095011245893717827001755139199539421256770251068054732628742653464707162470860867744644963513881626379295384868112521047478164340907648529396784829200044931951797398703223901613276374685005024596744539519881478197603392118613248423434290147783738349455206600361135767097728253899859300673023101217851592046508565998569554335284385533874213142078824927083941413815942201397168667551490343064477047456055738161122065405487954242757780650044346388918733082125581709373617193766794064656980908086996490008873091220888652781460009349617883870799390034720209402298176335296187821878769164995809396380376506331
To win the flag, submit r :)
8155
Great! :) please pass the next stage :P
n = 75216526271596365311583689648476617619334557709224915570712662525413220141371045989999405989638228739411340436002271022400381247452009561000639974705495587182612529351777097717361894152365141347947250740885976606619478983476894623670299192399177180129716452337872279277598532821198928032602650079360700842927323509917702246762441979641574097063576416656904964301927680248490944387995994161003221722158747368504184217682101852081020960491331222922857528086820561255265746827308708839025258945938509508169437710750389834308817065020082336679152444103349536529931359395079539701071935487151259384813056171879879517555672615959928424713596005783112836962659196492152031673232254654110625437249926218021974082625255380287031635856724897574407894876655832486245531944725225027594374293445689098205172530618340893154960824093925444630397011473557590448532064215621285079950285175
To win the flag, submit r :)
14
Great! :) please pass the next stage :P
n = 109663082557579957314455694977075611015747884106290102778850729721710104575094274235324451060911421761717718331882413733885744274850343420878696081584048247181046214892315391606024003354786054662249377678632586577713056745701166607529498278345746579790851739703298387607506170435901824582475185779036675531391240140276085855139067540648819178387
To win the flag, submit r :)
7423632694594406092782500625819012
Great! :) please pass the next stage :P
n = 588334255385556920933603368744437635265552701720661258181825549814157440887345039407764275447466968183792287805809886150808408670153932189299948446865649979103881307697092813707353891553936938800140371900425849458878165771292883754962173243336747771852533608966976979620999325399635100997728258626366044918508026114368427978354348607215753097906228006150869712874898919395624788577025895176028307988564456950422766256767359709154322320201484616292290537063841343690354024677937559124697194001925444305912835725670824029454310472193179621455267997047394594823746983176081674614834267106682520365722985390190882680831944374203461420959
To win the flag, submit r :)
7226762933174749005610338152233594024239337246
Great! :) please pass the next stage :P
n = 7679142641166565255095917848871911626457133586193968174930409925402706618434369752551165389517671470946020800744029131427767708161978734834769623349707042659147947364828123196767828464614045195803256968221340008975313967931131264963933022531035872220497783722670222475580564279044798495468640657259776902332702844388231289951144765623188840737110169116991493382496139979875863789945583293687288532942884251537481724446324204868067194057717835331654512731795253400395738977160030813543111687201120043
To win the flag, submit r :)
405542619814120497659187307652485433201479685770049178122950
Congratz! :) You got the flag: ASIS{36812f76cce2753e482ac6f68f9d3012}
フラグは、
ASIS{36812f76cce2753e482ac6f68f9d3012}