<?phpfunctioncurl($url){$ch=curl_init();curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_HEADER,0);curl_exec($ch);curl_close($ch);}if(isset($_GET['submit'])){$url=$_GET['url'];if(preg_match('/ctf\.cybersec/i',$url)){if(preg_match('/\@|\#|\?/i',$url)){die('not @#?');}else{$parts=parse_url($url);if(empty($parts['host'])||$parts['host']!='localhost'){exit('host must be localhost');}else{curl($url);}}}else{die("The URL must contain the 'ctf.cybersec'");}}?>
from Crypto.Util.number import *
import gmpy2
def GCRT(mi, ai):
assert (isinstance(mi, list) and isinstance(ai, list))
curm, cura = mi[0], ai[0]
for (m, a) in zip(mi[1:], ai[1:]):
d = gmpy2.gcd(curm, m)
c = a - cura
assert (c % d == 0) # 不成立则不存在解
K = c / d * gmpy2.invert(curm / d, m / d)
cura += curm * K
curm = curm * m / d
return (cura % curm, curm) # (解,最小公倍数)
n = 0x1d42aea2879f2e44dea5a13ae3465277b06749ce9059fd8b7b4b560cd861f99144d0775ffffffffffff
c = 421363015174981309103786520626603807427915973516427836319727073378790974986429057810159449046489151
p = 9749
q = 11237753507624591
r = n / p / q
e = 5
p_roots = [7361]
q_roots = [2722510300825886, 6139772527803903, 6537111956662153, 8415400986072042, 9898464751509789]
r_roots = [180966415225632465120208272366108475667934082405238808958048294287011243645, 2816114411493328258682873357893989007684496552202823306045771363205185148674391, 1369135259891793292334345751773139388112378132927363770631732500241630990458667, 5570877862584063114417410584640901580756179707042774516590562822938385811269597, 8499052407588078002885931765166137308397074232361087682974448633946350539292222]
m_list = []
for pp in p_roots:
for qq in q_roots:
for rr in r_roots:
res = GCRT([p, q, r], [pp, qq, rr])[0]
if pow(res, e, n) == c:
print long_to_bytes(res)
w 1 1 w
e 1 28657 5
a 2 2 a
d 3 1 e
f 5 3 d
a 8 17711 4
9 13 5 f
9 21 8 a
8 34 13 9
7 55 21 9
_ 89 46368 4
a 144 75025 f
d 233 34 8
w 377 55 7
d 610 89 _
2 987 610 d
3 1597 377 w
1 2584 144 a
2 4181 233 d
3 6765 1597 3
_ 10946 2584 1
4 17711 4181 2
5 28657 6765 3
4 46368 10946 _
f 75025 987 2
# encoding=utf-8
import random
from Crypto.Util.number import *
from fractions import gcd
def encrypt(msg, pkey):
msg, cipher = bin(bytes_to_long(msg))[2:], []
x, N = pkey
for bi in msg:
while True:
r = random.randint(1, N)
if gcd(r, N) == 1:
br = bin(r)[2:]
c = (pow(x, int(br + bi, 2), N) * r ** 2) % N
cipher.append(c)
break
return cipher
def make_key( nbit):
while True:
p, q = getPrime(nbit), getPrime(nbit)
N, phi = p * q, (p-1)*(q-1)
x = random.randint(1, N)
if (N % 8 == 1) and (phi % 8 == 4) and (p != q):
if pow(q ** 2 * x, (p-1)//2, p) + pow(p ** 2 * x, (q-1)//2, q) == N - phi - 1:
break
return (x, N), phi
nbit = 1024
flag="***********************"
pkey,phi = make_key(nbit)
enc = encrypt(flag, pkey)
print(phi)
print(pkey[1])
print(enc)
phi = 18073342511837221460079448265787741023290378482015904462054097159488609786118551016838958389332085278802940181664501460095771901689503087144086198024806833996959331959272928036293631801766532099133638473934624346682456553826961816725646976571715537813264251649134636027997268150627008143101806585720576666552635220727965475452561023341230361554614389710341110220435494577939628686397164534445789296520767510563355259756674795624672252282836525189327763381160669526729256266794057252303945538201386053860877451403413384500268425016376208183084659635450679557312534013090665435717767450483806884512373580050402177593284
n= 18073342511837221460079448265787741023290378482015904462054097159488609786118551016838958389332085278802940181664501460095771901689503087144086198024806833996959331959272928036293631801766532099133638473934624346682456553826961816725646976571715537813264251649134636027997268150627008143101806585720576666552904172009606714255109363340397696863030182973649760792591286879810816823051552478391349772534968660059990629735959534213237559806337995734039618031181129875558746748836156813833869014328267780457412036742252093026494670819741341288486468556796613523206153120383915932057403484789687833422119777623841915278529
p=(n-phi+1-((n-phi+1)^2-4*n).nth_root(2))//2
q=n//p
Fp=Integers(p)
enc=[太大了,这里略]
flag=[0 if Fp(f).is_square() else 1 for f in enc]
print(flag)