import sys from hashlib import md5 from binascii import * from secret import salt, flag
defdie(*args): pr(*args) quit()
defpr(*args): s = " ".join(map(str, args)) sys.stdout.write(s + "\n") sys.stdout.flush()
defsc(): return sys.stdin.buffer.readline()
defxor(s1, s2): returnbytes([s1[_] ^ s2[_] for _ inrange(len(s1))])
defmain(): border = "┃" pr( "┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓") pr(border, ".: Hi all, she did Mashy, you should do it too! Are you ready? :. ", border) pr( "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛")
REC = [] cnt, STEP = 0, 7 sh = md5(salt).digest()
whileTrue: pr(border, f'Please send your first input: ') d1 = sc().strip() pr(border, f'Please send your second input: ') d2 = sc().strip() try: d1 = hexlify(unhexlify(d1)) d2 = hexlify(unhexlify(d2)) h1 = md5(unhexlify(d1)).digest() h2 = md5(unhexlify(d2)).digest() except: die(border, 'Your inputs are not valid! Bye!!!') if d1 != d2 and d1 notin REC and d2 notin REC: if md5(xor(d1, d2)).hexdigest() != 'ae09d7510659ca40eda3e45ca70e9606': if hexlify(xor(xor(h1, h2), sh)) == b'a483b30944cbf762d4a3afc154aad825': REC += [d1, d2] if cnt == STEP: die(border, f'Congrats! the flag: {flag}') pr(border, 'Good job, try next level :P') cnt += 1 else: die(border, 'Your input is not correct! Bye!') else: die(border, 'No this one! Sorry!!') else: die(border, 'Kidding me!? Bye!!')
from Crypto.Util.number import * from flag import flag
defencrypt(msg, nbit): m, p = bytes_to_long(msg), getPrime(nbit) assert m < p e, t = randint(1, p - 1), randint(1, nbit - 1) C = [randint(0, p - 1) for _ inrange(t - 1)] + [pow(m, e, p)] R.<x> = GF(p)[] f = R(0) for i inrange(t): f += x**(t - i - 1) * C[i] P = [list(range(nbit))] shuffle(P) P = P[:t] PT = [(a, f(a)) for a in [randint(1, p - 1) for _ inrange(t)]] return e, p, PT
from Crypto.Util.number import * from random import * from secret import params, flag
defsol(m, a, z): p = m * (a - 1) % 2 + 1 whileTrue: R = list(range(1, a)) shuffle(R) for r in R[:z]: p += getRandomRange(0, 2) * m ** r if isPrime(p): return p else: p = m * (a - 1) % 2 + 1
p, q, r = [sol(*params) for _ in'007'] n = p * q * r m = bytes_to_long(flag) c = pow(m, params[0] ** 3 + params[2] - 2, n) print(f'n = {n}') print(f'c = {c}')
m = 19 for z inrange(2, 20): try: e = m ** 3 + z - 2 phin = (p-1)*(q-1)*(r-1) d = inverse(e, phin) m_ = long_to_bytes(pow(c, d, n)) if(b'CCTF'in m_): print(m_) except: pass
# b'CCTF{nUmb3r5_1N_D!fFerEn7_8As35_4r3_n!cE!?}'
成功。(还好最后没再来一个e和phin不互素...)
Joe-19
task
Python
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/env sage
from GPT import GPT6 # deep fake from Crypto.Util.number import * from flag import flag
P = [GPT6('A 512-bit prime appears in consecutive digits of e') for _ inrange(4)] n, m = prod(P), bytes_to_long(flag) c = pow(m, 0x10001, n) print(f'n = {n}') print(f'c = {c}')
# 遍历每一段 154 位长的数字,因为512bit在十进制下长度约为154 for i inrange(len(e_str) - 153): number_str = e_str[i:i + 154] number = int(number_str)
if isprime(number) and (n % number == 0): print(f"Found a prime number: {number}") break# 找到一个就退出
# 7728751393377105569802455757436190501772466214587592374418657530064998056688376964229825501195065837843125232135309371235243969149662310110328243570065781 from Crypto.Util.number import inverse,long_to_bytes
c = p = 7728751393377105569802455757436190501772466214587592374418657530064998056688376964229825501195065837843125232135309371235243969149662310110328243570065781
d = inverse(65537,p-1) m = pow(c,d,p) print(long_to_bytes(m))
from Crypto.Util.number import * from math import sqrt from flag import flag
defgen_params(nbit): p, Q, R, S = getPrime(nbit), [], [], [] d = int(sqrt(nbit << 1)) for _ inrange(d): Q.append(getRandomRange(1, p - 1)) R.append(getRandomRange(0, p - 1)) S.append(getRandomRange(0, p - 1)) return p, Q, R, S
defencrypt(m, params): p, Q, R, S = params assert m < p d = int(sqrt(p.bit_length() << 1)) C = [] for _ inrange(d): r, s = [getRandomNBitInteger(d) for _ in'01'] c = Q[_] * m + r * R[_] + s * S[_] C.append(c % p) return C
for i inrange(20): conn.recvuntil('send your') s = conn.recvline().decode() mat = re.search(pattern, s) bits = int(mat.group(1)) p, x, y = get_ans(bits) conn.sendline(f'{p}') conn.sendline(f'{x},{y}')
conn.interactive()
# Congratz! You got the flag: b'CCTF{Di0phaNtinE_eQuaT1on_iZ_4n_equ4tion_wiTh_int3ger_solu7Ions_0nly!}'