defadd(size,content): p.sendlineafter(b"Please input your choice:",b'1') p.sendlineafter(b"Please input the length of the diary content:",str(size)) p.recvuntil(b"Please enter the diary content:\n") p.send(content)
defdelete(): p.sendlineafter(b"Please input your choice:",b'3')
defedit(_size_,_payload_): p.sendlineafter(b"Please input your choice:",b'4') p.sendlineafter(b"Please input the length of the diary content:",str(size)) p.sendlineafter(b"content:",payload)
defshow(): p.sendlineafter(b"Please input your choice:",b'2')
one = [0x45226,0x4527a,0xf03a4,0xf1247]
p.sendlineafter(b'tell me your name.', b'name') add(0x108, b'a') # debug() edit(0x110, b'b' * 0x108 + p64(0xef1))
from Crypto.Util.number import * from secret import flag nbits = 512 p = getPrime(nbits) q = getPrime(nbits) n = p * q phi = (p-1) * (q-1) whileTrue: kk = getPrime(128) rr = kk + 2 e = 65537 + kk * p + rr * ((p+1) * (q+1)) + 1 if gcd(e, phi) == 1: break m = bytes_to_long(flag) c = pow(m, e, n)
e = e >> 200 << 200 print(f'n = {n}') print(f'e = {e}') print(f'c = {c}')
""" n = 111922722351752356094117957341697336848130397712588425954225300832977768690114834703654895285440684751636198779555891692340301590396539921700125219784729325979197290342352480495970455903120265334661588516182848933843212275742914269686197484648288073599387074325226321407600351615258973610780463417788580083967 e = 37059679294843322451875129178470872595128216054082068877693632035071251762179299783152435312052608685562859680569924924133175684413544051218945466380415013172416093939670064185752780945383069447693745538721548393982857225386614608359109463927663728739248286686902750649766277564516226052064304547032760477638585302695605907950461140971727150383104 c = 14999622534973796113769052025256345914577762432817016713135991450161695032250733213228587506601968633155119211807176051329626895125610484405486794783282214597165875393081405999090879096563311452831794796859427268724737377560053552626220191435015101496941337770496898383092414492348672126813183368337602023823 """
解题思路
有两个部分
1 2 3
e = 65537 + kk * p + rr * ((p+1) * (q+1)) + 1 if gcd(e, phi) == 1: break
PR.<x> = PolynomialRing(RealField(1000)) f = (kk+rr)*x**2 + (rr*n+65538)*x + rr*n - e*x res = f.roots() if res: print(res) for i in res: print(i[0]) print(int(i[0]))
n = 111922722351752356094117957341697336848130397712588425954225300832977768690114834703654895285440684751636198779555891692340301590396539921700125219784729325979197290342352480495970455903120265334661588516182848933843212275742914269686197484648288073599387074325226321407600351615258973610780463417788580083967 e = 37059679294843322451875129178470872595128216054082068877693632035071251762179299783152435312052608685562859680569924924133175684413544051218945466380415013172416093939670064185752780945383069447693745538721548393982857225386614608359109463927663728739248286686902750649766277564516226052064304547032760477638585302695605907950461140971727150383104 c = 14999622534973796113769052025256345914577762432817016713135991450161695032250733213228587506601968633155119211807176051329626895125610484405486794783282214597165875393081405999090879096563311452831794796859427268724737377560053552626220191435015101496941337770496898383092414492348672126813183368337602023823
rr = e // n kk = rr - 2
PR.<x> = PolynomialRing(RealField(1000)) f = (kk+rr)*x**2 + (rr*n+65538)*x + rr*n - e*x res = f.roots() if res: print(res) for i in res: # print(i[0]) # print(int(i[0])) P.<y> = PolynomialRing(Zmod(n)) h = int(i[0]) + y rt = h.monic().small_roots(X=2^200,beta=0.4) if rt: print(rt) for i in rt: p = ZZ(gcd(ZZ(h(i)),n)) print(p)
e = 65537 + kk * p + rr * ((p+1) * (q+1)) + 1 q = n // ZZ(p) d = pow(e,-1,(p-1)*(q-1)) m = pow(c,d,n) print(bytes.fromhex(hex(m)[2:]))
defshash(value): length = len(value) mask = 0xffffffffffffffff x = (value[0] << 7) & mask for c in value: x = (1000003 * x) & mask ^ c x ^= length & mask return x
""" def shash(value): length = len(value) mask = 0xffffffffffffffff x = (value[0] << 7) & mask for c in value: x = (1000003 * x) & mask ^ c x ^= length & mask return x """
defM1(a, b, c, d): x = (a << 7) & mask x = (1000003 * x) & mask ^ a x = (1000003 * x) & mask ^ b x = (1000003 * x) & mask ^ c x = (1000003 * x) & mask ^ d return x
defM2(p, m, r, y): y = (y ^ r) * invmask & mask y = (y ^ m) * invmask & mask y = (y ^ p) * invmask & mask return y
for i, j, k in itertools.product(range(256), repeat=3): m = M2(i, j, k, y=7457312583301101236) dic[m] = (i,j,k)
for a, b, c, d in itertools.product(range(256), repeat=4): m = M1(a, b, c, d) if m in dic: r = dic[m] print(b, c, d, r) print(f"{a:02x}{b:02x}{c:02x}{d:02x}{r[0]:02x}{r[1]:02x}{r[2]:02x}") break
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import hashlib from Crypto.Util.number import long_to_bytes key = b'5d8cf03f5a0852' c = 13903983817893117249931704406959869971132956255130487015289848690577655239262013033618370827749581909492660806312017
def process_file(input_file, output_file): try: with open(input_file, 'rb') as f: data = f.read()
# Extract every other byte new_data = data[::2]
with open(output_file, 'wb') as f: f.write(new_data)
print(f"Processed file saved as {output_file}")
except FileNotFoundError: print(f"Error: The file {input_file} does not exist.") except Exceptionas e: print(f"An error occurred: {e}")
# Usage input_file = 'inputfile'# replace with your input file name without suffix output_file = 'outputfile'# replace with your desired output file name without suffix process_file(input_file, output_file)