from base64 import b64encode, b64decode from Crypto.Util.number import bytes_to_long
f = open('flag.enc', 'rb') c = f.read() msg = 'CCTF{' ba = b64encode(msg.encode('utf-8'))
baph = '' for b in ba.decode('utf-8'): if b.islower(): baph += b.upper() else: baph += b.lower() baph = baph.encode('utf-8') print(baph) key = b'' for i inrange(len(baph)): key += (baph[i] ^ c[i]).to_bytes(1, 'big') key = key[:6]
flag = b'' for i inrange(len(c)): flag += (c[i] ^ key[i % len(key)]).to_bytes(1, 'big') msg = '' for f in flag.decode('utf-8'): if f.islower(): msg += f.upper() else: msg += f.lower() msg = msg.encode('utf-8') print(b64decode(msg)) #b'CCTF{UpP3r_0R_lOwER_17Z_tH3_Pr0bL3M}'
MEDIUM-EASY
sots
He who abides far away from his home, is ever longing for the day he shall return.
e = 31337 n = 44538727182858207226040251762322467288176239968967952269350336889655421753182750730773886813281253762528207970314694060562016861614492626112150259048393048617529867598499261392152098087985858905944606287003243 c = 37578889436345667053409195986387874079577521081198523844555524501835825138236698001996990844798291201187483119265306641889824719989940722147655181198458261772053545832559971159703922610578530282146835945192532
P = PolynomialRing(ZZ, 'k') k = P.gen() p = k**6 + 7*k**4 - 40*k**3 + 12*k**2 - 114*k + 31377 q = k**5 - 8*k**4 + 19*k**3 - 313*k**2 - 14*k + 14011 f = p*q -n x = f.roots()[0][0] #k = 9291098683758154336 p = p(x) q = q(x) phi = (p-1) * (q-1) d = gmpy2.invert(e,phi) print(long_to_bytes(pow(c,d,n)))
from Crypto.Util.number import long_to_bytes, bytes_to_long
n = 23087202318856030774680571525957068827041569782431397956837104908189620961469336659300387982516148407611623358654041246574100274275974799587138270853364165853708786079644741407579091918180874935364024818882648063256767259283714592098555858095373381673229188828791636142379379969143042636324982275996627729079 c = 3621516728616736303019716820373078604485184090642291670706733720518953475684497936351864366709813094154736213978864841551795776449242009307288704109630747654430068522939150168228783644831299534766861590666590062361030323441362406214182358585821009335369275098938212859113101297279381840308568293108965668609 e = 65537
p_high = bytes_to_long(b'CCTF{it_is_fake_flag_') p_low = bytes_to_long(b'_90OD_luCk___!!}') PR.<x> = PolynomialRing(Zmod(n)) f = p_high * 2^(43*8) + x * 2^(16*8) + p_low roots = f.monic().small_roots(X = 2^(27*8), beta = 0.4) p = int(f(roots[0])) assert n%p == 0 q = n//p d = inverse_mod(e, (p - 1) * (q - 1)) m = pow(c, d, n) print(long_to_bytes(m)) #b'Congratz, the flag is: CCTF{h0M3_m4dE_k3Y_Dr1vEn_CrYp7O_5ySTeM!}'
jeksign
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from pwn import * from random import randint
context(log_level = 'debug') nc = remote('02.cr.yp.toc.tf', 17113) x = 30 nc.recvuntil(b'-bit: \n') for i inrange(60): z = randint(2 ** (x-1), 2 ** x) print(z) nc.sendline(str(z**2)+','+str(z**2) + ',' + str(z)) x += 1 nc.recvline() #CCTF{4_diOpH4nT1nE_3Qua7i0n__8Y__Jekuthiel_Ginsbur!!}
print(len(st)) print(len(en)) res = b"" for i inrange(len(st)): if st[i] == en[i] and st[i] == " ": continue cc = bytes([(ord(en[i]) - ord(st[i])) % 26 + ord('A')]) ifb"Z" == cc: res += b" " else: res += cc print(res)