from Crypto.Util.number import * from tqdm import * import gmpy2
c = 6451324417011540096371899193595274967584961629958072589442231753539333785715373417620914700292158431998640787575661170945478654203892533418902 n = 178981104694777551556050210788105224912858808489844293395656882292972328450647023459180992923023126555636398409062602947287270007964052060975137318172446309766581 phi = 1 e = 65537 primes = [] for i in factor(n): primes.append(i[0]) for i in trange(len(primes)): print(f"i={i}") for j inrange(1,len(primes)): if i!=j: really_n = n // (primes[i]*primes[j]) phi = euler_phi(really_n) d = gmpy2.invert(e,phi) m = pow(c,d,really_n) flag = long_to_bytes(int(m)) ifb"begin"in flag: print(flag) break # begin{y0u_f1nd_th3_re4l_n}
from Crypto.Util.number import * from flag import flag
assertlen(flag) == 64
classRSA(): def__init__(self, m: int): self.p, self.q, self.e, self.m = getPrime(256), getPrime(256), getRandomRange(1,9), m self.n = self.p * self.q defPublickey(self): return (self.n, self.e,self.c) defEncrypt(self): pad = PAD(m=self.m, e=0) pad.PAD() self.c = (pad.e,pow(pad.M, self.e, self.n)) classPAD(): def__init__(self, m: int, e): self.e, self.m, self.mbits = e, m, m.bit_length() if e == 0: self.e = getRandomRange(1, 9) defPAD(self): self.M = pow(self.e, self.mbits) + pow(self.m, self.e) GIFT = bytes_to_long(flag)
withopen("GIFT.txt", "w") as f: for i inrange(100): rsa = RSA(m=GIFT) rsa.Encrypt() data=rsa.Publickey() if data[1]*data[2][0]<=2: continue f.write(str(data) + "\n")
mbits=79*8+7 withopen("output.txt","r") as f: data=[eval(i) for i in f.readlines()]
for k inrange(2,20): n,e,c=[],[],[] for i inrange(len(data)): if data[i][1]*data[i][2][0]==k: n.append(data[i][0]) e.append((data[i][1],data[i][2][0])) c.append(data[i][2][1]) iflen(c)>=7: break
# print(n) # print(e) # print(c)
bit = 511 N = prod(n) temp = [[1if i == j else0for i inrange(len(e))] for j inrange(len(e))] T = [CRT_list(temp[i],n) for i inrange(len(e))] pad = [pow(e[i][-1],bit) for i inrange(len(e))]
g = T[0]*f0 + T[1]*f1 + T[2]*f2 + T[3]*f3 + T[4]*f4 + T[5]*f5 + T[6]*f6 g = g.monic() roots = g.small_roots(X=2^511,epsilon=0.03) print(roots) for i in roots: flag = long_to_bytes(int(i)) ifb"begin"in flag: print(flag)
OEIS2
task.py
1 2 3 4 5 6 7
from hashlib import *
upper = 2**28 + 5 res = 1 for i inrange(1, upper + 1): res *= i flag = 'Beginctf{' + sha256(str(sum([int(i) for i instr(res)])).encode()).hexdigest() + '}'
半途换了附件有点难受,对着$n^n$查了很久
利用gamma函数近似计算阶乘:$\gamma(n+1) = n!$
然后计算每位数之和
时间要比较久,耐心等等
exp:
1 2 3 4 5 6 7 8 9 10 11 12 13
from hashlib import * from tqdm import tqdm
x = 2^28 + 5 temp = str(gamma(x+1))
res = 0 for i in tqdm(temp): res += int(i) flag = 'Beginctf{' + sha256(str(res).encode()).hexdigest() + '}' print(flag) # Beginctf{c60a2e5c9e9572ed848776f282a9c90d6ca0fe29f8308b0b9b43c61d493133e9}
我玩青水的
task.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from Crypto.Util.number import * from secret import flag
m = bytes_to_long(flag) e = 2 p = getPrime(512) c = pow(m, e, p)
print(f"p = {p}") print(f"c = {c}")
''' p = 7709388356791362098686964537734555579863438117190798798028727762878684782880904322549856912344789781854618283939002621383390230228555920884200579836394161 c = 5573755468949553624452023926839820294500672937008992680281196534187840615851844091682946567434189657243627735469507175898662317628420037437385814152733456 '''
import gmpy2 from Crypto.Util.number import * import sympy
p = 7709388356791362098686964537734555579863438117190798798028727762878684782880904322549856912344789781854618283939002621383390230228555920884200579836394161 a = 5573755468949553624452023926839820294500672937008992680281196534187840615851844091682946567434189657243627735469507175898662317628420037437385814152733456 e = 2 k = 0
P = p - 1 if p % 4 == 3: print(pow(a,(p + 1)//4,p)) else: while P % 2 == 0: P //= 2 k += 1 q = 2 while q: l = pow(q,(p-1)//2,p) if l == p - 1: break q = sympy.nextprime(q) b = pow(q,P,p) x = [0for i inrange(k)] re_a = gmpy2.invert(a,p) x[k-1] = pow(a,(P+1)//2,p) for i inrange(1,k): m = re_a * pow(x[k-i],2) n = pow(2,(k-i-1)) ifpow(m,n,p) == p-1: j0 = 1 x[k-i-1] = x[k-i]*pow(b,j0*(2**(i-1))) % p else: j1 = 0 x[k-i-1] = x[k-i] % p print(long_to_bytes(x[0])) # begin{quadr4ticresidue_i5_s0_3asy}