defstring2num(v): n = 0 s = v.find("拾") if s == 0: n += 1000 v = v[1:] elif s == 1: n += 1000 * d[v[0]] v = v[2:] s = v.find("元") if s == 1: n += d[v[0]] * 100 v = v[2:] elif s == 0: v = v[1:]
s = v.find("角") if s == 1: n += d[v[0]] * 10 v = v[2:] s = v.find("分") if s >= 1: n += d[v[s-1]] v = v[2:] return n/100
f = 'bills.xlsx' wb = xlrd.open_workbook(f) s = wb.sheet_by_index(0) values = s.col_values(0)[1:] nums = s.col_values(1)[1:] l = [] f = xlwt.Workbook() sheet1 = f.add_sheet('t',cell_overwrite_ok=True) for v in values: if"佰"in v: l.append(tmp.pop(0)) else: l.append(string2num(v)) #print(v, string2num(v))
a = 0.0 for i inrange(len(l)): sheet1.write(i+1,0,l[i]) a += l[i] * nums[i] print(a) f.save("test.xls")
超简单的世界模拟器
图灵完备的浪漫
蝴蝶效应
在 Wikipedia 上搜到了一个会爆炸的初始状态,于是就在左上角随便挑了几个位置尝试一下,最后得到了左上角位于 (5, 6) 的图形可以满足题目要求:
defshow(a): rm, cm = a.shape for r inrange(rm): for c inrange(cm): print("o"if a[r][c] else".", end="") print() print()
defnext(a): b = np.pad(a,((1, 1),(1, 1)),'constant',constant_values = (0,0)) rm, cm = a.shape for r inrange(rm): for c inrange(cm): s = np.sum(b[r:r+3, c:c+3]) - a[r][c] a[r][c] = int((s == 2and a[r][c]) or s == 3)
whileTrue: a = np.zeros((50,50), dtype=int) a[5:7,45:47] = 1 a[25:27,45:47] = 1 while np.sum(a[5:7,45:47]) + np.sum(a[25:27,45:47]) != 0: a = np.zeros((50,50), dtype=int) a[5:7,45:47] = 1 a[25:27,45:47] = 1
for r inrange(15): for c inrange(15): a[r][c] = int(np.random.random() < 1/3) withopen(f"life.txt", "w") as f: for r inrange(15): for c inrange(15): f.write(str(a[r][c])) f.write("\n")
bool success = false; // human wins? char input[128] = {}; // input is large and it will be ok. // ... gets(input); // ... if (success) { puts("What? You win! Here is your flag:"); flag_decode(); puts(flag); }
UA = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" headers = {} headers["User-Agent"] = UA headers["Authorization"] = "Bearer 708:"# token here
defcreate_credit(): data = {"type": "credit"} req = requests.post("http://202.38.93.111:10100/api/create", headers=headers, json=data)
defcreate_debit(): data = {"type": "debit"} req = requests.post("http://202.38.93.111:10100/api/create", headers=headers, json=data)
defnext_day(account): data = {"account": account} req = requests.post("http://202.38.93.111:10100/api/eat", headers=headers, json=data)
definit(): for i inrange(9): create_credit() # credit cards from 2 to 10 transfer(i+2, 1, 2099) print("credit created #%d " % (i+2), end="\r") for i inrange(119): create_debit() transfer(1, i+11, 167) # debit cards from 11 to 129 print("debit created #%d " % (i+11), end="\r") next_day(1)
defday(): for i inrange(119): transfer(i+11, 1, 1) for i inrange(9): transfer(1, i+2, 10) next_day(1)
#print("----------Day 1----------") #init() for i inrange(50): print("----------Day %d----------" % (i+1)) day()
import requests import urllib, time from func_timeout import func_set_timeout, FunctionTimedOut import re from sympy import sin, sinh, cos, cosh, ln, sqrt, N, integrate, sqrt, tan, atan, acos, asin, tanh from sympy.abc import x, e
UA = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" headers = {} headers["User-Agent"] = UA
deffindpairs(l, f, n): left = 0 right = 0 count = 0 for i inrange(f, len(l)): w = l[i] if w == "{": left += 1 elif w == "}": right += 1 if left == right and left != 0: count += 1 if count >= n: return i
defdisfrac(s): a = s.find("{") b = findpairs(s, a, 1) u = s[a+1: b] s = s[b+1:] a = s.find("{") b = findpairs(s, a, 1) l = s[a+1: b] return u, l
req = ""
defval(s): if"\\frac"in s: u, l = disfrac(s) returnfloat(eval(u) / eval(l)) else: returneval(s)
@func_set_timeout(5) defsolve_page(): n = 0 while(n < 10): try: withopen("solid_math_cookie.txt", "r") as f: cookie = f.read() headers["Cookie"] = cookie req = requests.get("http://202.38.93.111:10190/", headers=headers, timeout=2) headers["Cookie"] = req.headers["Set-Cookie"].split(";")[0] a = req.text print(a) break except Exception as e: n += 1 print("ERROR: Error for the %d time, exception type: %s" % (n, e)) time.sleep(5) if n == 10: returnFalse r = re.compile(r'<p>(.*?)</p>') formula = r.findall(a)[0]
formula = formula[:-8] c = formula.find("^") lower = val(formula[8:c-1]) formula = formula[c:]
c = formula.find(" ") upper = val(formula[2:c-1]) formula = formula[c+1:]
while"\\frac"in formula: f = formula.find("\\frac") end = findpairs(formula, f, 2) s = "{0[0]}/{0[1]}".format(disfrac(formula[f: end+1])) formula = formula[:f] + s + formula[end+1:] formula = formula.replace("\\, ", "*") formula = formula.replace("\\left", "") formula = formula.replace("\\right", "") while"arcsin"in formula: f = formula.find("arcsin") for i inrange(f-1, 0, -1): w = formula[i] if w in [" ", "\\"]: continue if w in [")", "x"] + [str(_) for _ inrange(10)]: formula = formula[:f] + "*asin" + formula[f+6:] else: formula = formula[:f] + "asin" + formula[f+6:] break while"arccos"in formula: f = formula.find("arccos") for i inrange(f-1, 0, -1): w = formula[i] if w in [" ", "\\"]: continue if w in [")", "x"] + [str(_) for _ inrange(10)]: formula = formula[:f] + "*acos" + formula[f+6:] else: formula = formula[:f] + "acos" + formula[f+6:] break while"arctan"in formula: f = formula.find("arctan") for i inrange(f-1, 0, -1): w = formula[i] if w in [" ", "\\"]: continue if w in [")", "x"] + [str(_) for _ inrange(10)]: formula = formula[:f] + "*atan" + formula[f+6:] else: formula = formula[:f] + "atan" + formula[f+6:] break
while"^"in formula: f = formula.find("^") end = findpairs(formula, f, 1) formula = formula[:f] + "**(" + formula[f+2:end] + ")" + formula[end+1:]
while"\\sqrt"in formula: f = formula.find("\\sqrt") end = findpairs(formula, f, 1) formula = formula[:f] + "sqrt(" + formula[f+6:end] + ")" + formula[end+1:]
while"\\ln"in formula: f = formula.find("\\ln") for i inrange(f-1, 0, -1): w = formula[i] if w == " ": continue if w in [")", "x"] + [str(_) for _ inrange(10)]: formula = formula[:f] + "*ln" + formula[f+3:] else: formula = formula[:f] + "ln" + formula[f+3:] break
formula = formula.replace("\\", "")
while"{"in formula: f = formula.find("{") end = findpairs(formula, f, 1) before = "" after = "" for i inrange(f-1, 0, -1): w = formula[i] if w == " ": continue if w notin ["+", "-", "*", "/"]: before = "*" break for i inrange(end+1, len(formula)): w = formula[i] if w == " ": continue if w notin ["+", "-", "*", "/"]: after = "*" break formula = formula[:f] + before + formula[f+1:end] + after + formula[end+1:] formula = formula.replace(" ", "")
print("lower: %.2f upper: %.2f len: %d formula: %s" % (lower, upper, len(formula), formula)) iflen(formula) > 35: returnFalse try: res = N(integrate(eval(formula),(x,lower,upper)), 12) res = round(res, 6) print("answer:", res) except Exception as e: print(e) returnFalse data = {"ans":res} req = requests.post("http://202.38.93.111:10190/submit", headers=headers, data=data) cookie = req.headers["Set-Cookie"].split(";")[0] headers["Cookie"] = cookie t = req.text t = t[t.find("答案"):] print(t[:t.find("\n")]) i = t.find("题") print(t[i-4:i+1]) withopen("solid_math_cookie.txt", "w") as f: f.write(cookie) returnTrue
solve_page()
永不溢出的计算器
Python,大整数计算的神!
首先计算 0−1 就可以得到 n−1 的值,那么为了得到 flag 我们就需要对 n 进行质因数分解。
观察题面,发现加减乘除和乘方这些运算只需要 n 的值就可以简单的完成,但开方是什么情况?随机生成一些比较大的完全平方数 x2 发现在开方后的结果 y 并不是 x 或者 −x(n−x)。在这种情况下我们可以得到一组 x2≡y2modn,也就是 n∣x2−y2,或者说 n∣(x−y)(x+y)。ん?
因为这里 x,y∈(0,n),所以他们的和以及差都不可能是 n 的倍数。但他们的乘积却能被 n 整除,那么他们必定各包含一个 n 的因数。用辗转相除法计算 gcd(n,x±y) 即可得到其中一个因数,之后用标准的 RSA 解密就可以得到 flag 啦。
print(conn.connect()) response = conn.get_response() for push in conn.get_pushes(): # all pushes promised before response headers print(push.path) conn.read() for push in conn.get_pushes(): # all other pushes print(push.path)
withopen("gibberish_message.txt", "rb") as f: a = f.read() a = a.replace(b"\n", b"").replace(b" ", b"") print(a) b = bytes(a.decode("utf8").encode("gbk")) print(b) l = [] f = open("g.txt", "w") ifTrue: for i inrange(len(b)): if i % 2 == 0: l.append(((b[i]&3)<<6)+(b[i+1]&0x3f)) print(bytes(l)) #f.write(bytes(l).decode("gbk") + "\n") #print(bytes(l).decode("gbk")) print(min(l), max(l), max(l) - min(l))
f.close()
生活在博弈树上
年轻人的第一款 ROP
升上天空
第一次接触 pwn,能搞明白栈溢出已经很不错了,能干掉第二问的 ROP 属实有点幻想了。不过赛后花了点时间从头了解了一遍,也是成功的构建出 get shell 的 payload 了。
import cv2, zbar import os path ='.' defget_filelist(dir): Filelist = [] for home, dirs, files in os.walk(path): for filename in files: Filelist.append(filename) return Filelist
files = get_filelist(path)
withopen("out", "wb") as f: for filename in files: ifnot"png"in filename: continue img = cv2.imread(filename, 0) scanner = zbar.Scanner() results = scanner.scan(img) f.write(results[0].data)
解压得到的 out 文件可以看到正确的 META 和 COMMITS,甚至还能看到这样一条 commit: “There’s no flag in META and COMMITS!”。但是查看应该存有数据的 repo.tar.xz,发现怎么完全解压不了啊?…于是就卡在这里了。
o = "E" rights = ["(E+E)", "(E-E)", "(E*E)", "(E//E)", "(E%E)", "(E^E)", "(E&E)", "(E|E)"] singles = ["(-E)", "(~E)"]
A = 5
e = [[] for _ inrange(6)] e[0] = [o] for j inrange(1, A): tmp = [_ for _ in e[j-1]] for exp in e[j-1]: for i inrange(len(exp)): if exp[i] == "E": for single in singles: tmp.append(exp[:i] + single + exp[i+1:]) e[j-1] = tmp for exp in e[j-1]: for i inrange(len(exp)): if exp[i] == "E": for right in rights: e[j].append(exp[:i] + right + exp[i+1:])
print("calculating results")
res = [[] for _ inrange(6)] d = [Falsefor _ inrange(114514)] f = open("log.txt", "w") for I inrange(A): print(I) for exp in e[I]: for perm in seg[I]: before = 0 r = "" j = 0 for i inrange(len(exp)): if exp[i] == "E": r += exp[before:i] + str(perm[j]) j += 1 before = i+1 r += exp[before:] try: v = eval(r) if v >= 0andnot d[v]: d[v] = True print(v, r) f.write(str(v) + " = " + r.replace("//", "/") + "\n") except: pass f.close()