from Crypto.Util.number import getPrime, isPrime, bytes_to_long import os
def 0psu3_The_best(sz, d): whileTrue: p = getPrime(sz) pp = sum([p**i for i inrange(d)]) if isPrime(pp): return p, pp
p, q = 0psu3_The_best(512, 5) r = getPrime(512 * 5) n = p * q * r e = 65537 flag=open("flag.txt", "rb").read().strip() flag1=flag+os.urandom(128) m=bytes_to_long(flag1)
whileTrue: Q = R.quo(R.random_element(5)) res = gcd(int(list(Q.random_element() ^ n)[1]), n) if res > 1: p = res q = p^4 + p^3 + p^2 + p + 1 r = n // (p*q) assert p * q * r == n phi = (p-1)*(q-1)*(r-1) d = inverse(e, phi) m = pow(c, d, n) print(long_to_bytes(int(m))) break # DASCTF{just_a_very_very_easy_task_with_your_talent_is_not}
from Crypto.Util.number import * from gmpy2 import *
P = getPrime(int(512)) p_list=[]
for i inrange(30): q=getPrime(1024) r=getPrime(450) l=q*P+r p_list.append(l) path1="D:/CTF题目\密码\出题1/" withopen("output.txt",'w')as f1: for val in p_list: f1.write(str(val)) f1.write("\n")
R.<x> = PolynomialRing(Zmod(P)) f = x^7 - m_7 f = f.monic() res1 = f.roots()
R.<x> = PolynomialRing(Zmod(Q)) f = x^1337 - m_1337 f = f.monic() res2 = f.roots()
for i in res1: for j in res2: m = CRT_list([int(i[0]),int(j[0])],[P,Q]) flag = long_to_bytes(int(m)) ifb"DASCTF"in flag: print(flag) break # DASCTF{VERY_VERY_EASY_AND_TAKE_THE_NEXT_TIME}
from random import randint from Crypto.Util.number import * from secret import flag defencrypt(key, message, mask): returnpow(64901, message^^mask, key) defget_Prime_leak(bits,t1): x,y=0,1 whileTrue:
u=randint(1,200) v=randint(1,200) x,y=u*x+t1*v*y,v*x-u*y ifint(x).bit_length()<=bits//2: p=x^2+t1*y^2|1 if isPrime(int(p)) andint(p).bit_length()>=bits: return p else: x,y=0,1 t1=getPrime(16) print(f"t1={t1}") p=get_Prime_leak(512,t1) q=get_Prime_leak(512,t1) assert p>q n=p*q print(f"n={n}") flag=bytes_to_long(flag) messages = [getRandomNBitInteger(flag.bit_length()) for i inrange(200)] enc = [encrypt(p, message, flag) for message in messages]
for i in roots: plow = int(i[0]) R.<x> = PolynomialRing(Zmod(n)) f = x * 2^300 + plow f = f.monic() res = f.small_roots(2^212,beta=0.4) if res: p = int(res[0])*2^300 + plow q = n // p d = gmpy2.invert(e,(p-1)*(q-1)) m = pow(c,d,n) print(long_to_bytes(int(m))) #DASCTF{0psu3_is_the_most_Greatest_army} break