這幾天準備模考有點累,剛好看到有好玩的CTF,主要還是打crypto,這次8題打出5題,覺得還行,找幾題有趣的題目寫writeup。
I’ve been a bit tired these days preparing for the GSAT, and I happened to come across an interesting CTF. I mainly focused on crypto challenges. There were 8 problems this time, and I solved 5 of them, which I think is pretty decent. I’m planning to write writeups for a few of the more interesting ones.
rot727h3
i rotated my flag 727 times! that’s super secure right
aeg{at_imuf_nussqd_zgynqd_paqezf_yqmz_yadq_eqogdq}
就凱撒加密 Caesar Cipher
Flag: osu{oh_wait_bigger_number_doesnt_mean_more_secure}
ssssh3
can you ss this secret sharing scheme?
nc ssss.challs.sekai.team 1337
#!/usr/local/bin/python3from Crypto.Util.number import *import random
p = 2**255 - 19k = 15SECRET = random.randrange(0, p)
def lcg(x, a, b, p): return (a * x + b) % p
a = random.randrange(0, p)b = random.randrange(0, p)poly = [SECRET]while len(poly) != k: poly.append(lcg(poly[-1], a, b, p))
def evaluate_poly(f, x): return sum(c * pow(x, i, p) for i, c in enumerate(f)) % p
print("welcome to ssss", flush=True)for _ in range(k - 1): x = int(input()) assert 0 < x < p, "no cheating!" print(evaluate_poly(poly, x), flush=True)
if int(input("secret? ")) == SECRET: FLAG = open("flag.txt").read() print(FLAG, flush=True)解法:h4
假設質數
現有一個未知的 次多項式
其係數滿足遞推關係:
我們可以查詢 在任意 個非零點的值,目標是求出 。
首先,對 在 個非零點進行查詢,可以得到包含 的 條線性方程式。
由於變數共有 個,透過高斯消元可以將每個 表示為 的線性函數。
由遞推關係可得:
將前一步的線性表示代入,可得到一個關於 的二次方程式。
最後,在 下對此二次方程求解,並透過二次剩餘檢查來確定正確的 。
Solution:h4
Assume the prime
We have an unknown degree- polynomial
whose coefficients satisfy the recurrence:
We are allowed to query the value of at any non-zero points, and the goal is to determine .
First, by querying at distinct non-zero points, we obtain linear equations involving .
Since there are variables in total, we can use Gaussian elimination to express each as a linear function of .
From the recurrence relation we have:
Substituting the linear expressions obtained above yields a quadratic equation in .
Finally, we solve this quadratic equation modulo and determine the correct solution by checking quadratic residues.
Flag: osu{0n3_hundr3d_p3rc3nt_4ccur4cy!}
Comments