from Crypto.Util.number import long_to_bytes import hashlib import binascii
mask = 0xffffffffffffffff res = 7457312583301101235 cipher = 13903983817893117249931704406959869971132956255130487015289848690577655239262013033618370827749581909492660806312017 MOD = 2^64 a = 1000003
from random import randint from Crypto.Util.number import getPrime
defgen_param(x, p, BITS): r = getPrime(BITS//2) whileTrue: q = getPrime(BITS) if q < p: break b = (x * q + r) % p return r, b, q
defgen_key(BITS): p = getPrime(BITS) x = randint(1, p-1) sk = [x] pk = [p] for _ inrange(2): r, b, q = gen_param(x, p, BITS) sk.append(r) pk.extend([b, q]) return sk, pk
if __name__ == "__main__": print("welcome to my game, you need to pass 10 rounds to get the flag") round = 10 for _ inrange(round): sk, pk = gen_key(256) x = sk[0] print("pk: ", pk) x_ = int(input("give me x: ")) if x_ == x: print("good") else: print("wrong!") exit(0) print("congratulation, here is your flag") withopen("flag.txt") as f: print(f.read())
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 """
defget_p(phigh,n): PR.<x> = PolynomialRing(Zmod(n)) f = x + phigh roots = f.monic().small_roots(X = 2^200,beta=0.4) if roots: x0 = roots[0] p = int(x0) + phigh assert isPrime(p) return p n = 111922722351752356094117957341697336848130397712588425954225300832977768690114834703654895285440684751636198779555891692340301590396539921700125219784729325979197290342352480495970455903120265334661588516182848933843212275742914269686197484648288073599387074325226321407600351615258973610780463417788580083967 e = 37059679294843322451875129178470872595128216054082068877693632035071251762179299783152435312052608685562859680569924924133175684413544051218945466380415013172416093939670064185752780945383069447693745538721548393982857225386614608359109463927663728739248286686902750649766277564516226052064304547032760477638585302695605907950461140971727150383104 c = 14999622534973796113769052025256345914577762432817016713135991450161695032250733213228587506601968633155119211807176051329626895125610484405486794783282214597165875393081405999090879096563311452831794796859427268724737377560053552626220191435015101496941337770496898383092414492348672126813183368337602023823
k = e // n - 2 print(k) a = 65537 + (k+2)*n + (k+2) + 3
R.<x> = PolynomialRing(RealField(1024)) f = e*x - (2*(k+1)*x^2 + (k+2)*n + a*x) res = f.roots()
for root in res: p_high = int(root[0]) p_high = p_high >> 200 << 200 p = get_p(p_high,n) if p != None: q = n // p e = 65537 + k * p + (k+2) * ((p+1) * (q+1)) + 1 d = inverse(e,(p-1)*(q-1)) m = pow(c,d,n) print(long_to_bytes(int(m))) # flag{b5f771c6-18df-49a9-9d6d-ee7804f5416c}
from Crypto.Util.number import * from Crypto.PublicKey import RSA import random from secret import flag
m = bytes_to_long(flag) key = RSA.generate(1024) passphrase = str(random.randint(0,999999)).zfill(6).encode() output = key.export_key(passphrase=passphrase).split(b'\n') for i inrange(7, 15): output[i] = b'*' * 64 withopen("priv.pem", 'wb') as f: for line in output: f.write(line + b'\n') withopen("enc.txt", 'w') as f: f.write(str(key._encrypt(m)))
from tqdm import * from Crypto.Util.number import * from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_OAEP
n = 0xa18f011bebacceda1c6812730b9e62720d3cbd6857af2cf8431860f5dc83c5520f242f3be7c9e96d7f96b41898ff000fdb7e43ef6f1e717b2b7900f35660a21d1b16b51849be97a0b0f7cbcf5cfe0f00370cce6193fefa1fed97b37bd367a673565162ce17b0225708c032961d175bbc2c829bf2e16eabc7e0881feca0975c81 e = 65537 dq_leak= 0x8f2363b340e5 inv = 0x5f152c429871a7acdd28be1b643b4652800b88a3d23cc57477d75dd5555b635167616ef5c609d69ce3c2aedcb03b62f929bbcd891cadc0ba031ae6fec8a2116d c = 55149764057291700808946379593274733093556529902852874590948688362865310469901900909075397929997623185589518643636792828743516623112272635512151466304164301360740002369759704802706396320622342771513106879732891498365431042081036698760861996177532930798842690295051476263556258192509634233232717503575429327989
defcoppersmith(k): R.<x> = PolynomialRing(Zmod(n)) tmp = e * (x * 2^48 + dq_leak) + k - 1# kq f = inv * tmp^2 - k*tmp f = f.monic() x0 = f.small_roots(X=2^464,beta=1,epsilon=0.09) return x0
for k in trange(1,e): x0 = coppersmith(k) if x0 != []: dq = int(x0[0]) * 2^48 + dq_leak q = (e*dq + k - 1) // k # print(f"k = {k}") # k = 47794 p = n // q d = inverse(e,(p-1)*(q-1)) m = pow(c,d,n) print(long_to_bytes(int(m))) # b'flag{df4a4054-23eb-4ba4-be5e-15b247d7b819}' break