Skip to content

flag is captured! #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 43 additions & 47 deletions tmu_ctf_too_many_challenge/challenge.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
numbers = []
print ('starting')
with open("numbers.txt") as f:
content = f.readlines()
for n in content:
numbers.append(int(n.strip()))
print ('numbers are ready')

def func(x):
print ('func started for %s' % x)
# Returns the number of distinct pairs (y, z) from the numbers in the file "numbers.txt" whose y != z and (y + z) == x
# Note that two pairs (y, z) and (z, y) are considered the same and are counted only once
ans = set()
step = 0
for i in numbers:
j = x - i # we are looking for j where j+i == x
if j in numbers:
if j == i:
continue
elif j > i:
ans.add((j,i))
else:
ans.add((i,j))
return len(ans)


def get_flag(res):
flag = []
for i in range(len(res)):
flag.append(chr(func(res[i])))
flag = ''.join(flag)
return flag


if __name__ == "__main__":
res = [751741232, 519127658, 583555720, 3491231752, 3333111256, 481365731, 982100628, 1001121327, 3520999746,
915725624, 3218509573, 3621224627, 3270950626, 3321456817, 3091205444, 999888800, 475855017, 448213157,
3222412857, 820711846, 3710211491, 3119823672, 3333211607, 812955676, 971211391, 3210953872, 289789909,
781213400, 578265122, 910021887, 653886578, 3712776506, 229812345, 582319118, 1111276998, 1151016390,
700123328, 1074521304, 3210438183, 817210125, 501231350, 753244584, 3240911853, 415234677, 469125436,
592610671, 612980665, 291821367, 344199617, 1011100412, 681623864, 897219249, 3132267885, 565913000,
301203203, 3100544737, 432812663, 1012813485, 510928797, 671553831, 3216409218, 3191288433, 698777123,
3512778698, 810476845, 3102989588, 3621432709, 812321695, 526486561, 378912454, 3316207359, 623111580,
344209171, 537454826, 691277475, 2634678623, 1112182335, 792111856, 762989676, 666210267, 871278369,
581009345, 391231132, 921732469, 717217468, 3101412929, 3101217354, 831912337, 532666530, 701012510,
601365919, 492699680, 2843119525]
print("The flag is", get_flag(res))

numbers = []
def read_numbers():
global numbers
with open('numbers.txt','rt') as fid:
numbers = {int(line.split()[0]) for line in fid.readlines()}

def func(x):
# Returns the number of distinct pairs (y, z) from the numbers in the file "numbers.txt" whose y != z and (y + z) == x
# Note that two pairs (y, z) and (z, y) are considered the same and are counted only once
global numbers
if len(numbers) == 0:
read_numbers()
k = 0
for y in numbers:
z = x - y
if z > 0 and z in numbers:
k += 1
k = int(k / 2)
print('got {} result {}'.format(x,k))
return k

def get_flag(res):
flag = []
for i in range(len(res)):
flag.append(chr(func(res[i])))
flag = ''.join(flag)
return flag


if __name__ == "__main__":
res = [751741232, 519127658, 583555720, 3491231752, 3333111256, 481365731, 982100628, 1001121327, 3520999746,
915725624, 3218509573, 3621224627, 3270950626, 3321456817, 3091205444, 999888800, 475855017, 448213157,
3222412857, 820711846, 3710211491, 3119823672, 3333211607, 812955676, 971211391, 3210953872, 289789909,
781213400, 578265122, 910021887, 653886578, 3712776506, 229812345, 582319118, 1111276998, 1151016390,
700123328, 1074521304, 3210438183, 817210125, 501231350, 753244584, 3240911853, 415234677, 469125436,
592610671, 612980665, 291821367, 344199617, 1011100412, 681623864, 897219249, 3132267885, 565913000,
301203203, 3100544737, 432812663, 1012813485, 510928797, 671553831, 3216409218, 3191288433, 698777123,
3512778698, 810476845, 3102989588, 3621432709, 812321695, 526486561, 378912454, 3316207359, 623111580,
344209171, 537454826, 691277475, 2634678623, 1112182335, 792111856, 762989676, 666210267, 871278369,
581009345, 391231132, 921732469, 717217468, 3101412929, 3101217354, 831912337, 532666530, 701012510,
601365919, 492699680, 2843119525]
print("The flag is", get_flag(res))