sys.setrecursionlimit(1000000) def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m c2=33779700221348135863883889808859563343423001889653007646555069516716259945612034733082561959883961917662442280291944562628883748407830474721742306313000702967971453373637827273515616724662511317244698194870689547692454885460872111009447484052870214525773772949797440252321711833250575503307765208772617173270 n2=96644761669624481301917738904558511784349689869284077227291095697383603370416696531038428870514904299839725620796103329082259883963293954990250648331621341612726931174557257677636896537544958896292649989756895190445785876393803989356576607112504335129072639030916034557841042095819625963688752801565503231051 e2=0x101 c3=30751047399313667982517938591543296360089165396123556639822192850466091408760212776242161290545404062143092058831777133453019026398775795321668225155960973377187125716966663728065553458641296126185722656640906185814271035328849549938786034165849397581790764362592273425592482065323159559623654210395502163654 e3=0x10001 s = egcd(e2, e3) s1 = s[1] s2 = s[2] if s1<0: s1 = - s1 c2 = modinv(c2, n) elif s2<0: s2 = - s2 c3 = modinv(c3, n2) msg2=(pow(c2,s1,n2)*pow(c3,s2,n2)) % n2 print (binascii.unhexlify(hex(msg2)[2:].strip("L")))
得出结果
1 2
$b'Tanabata Festival, also known as Qiqiao Festival, ' $b"Qijie Festival, daughter's day, Qiqiao Festival, Qiniang society, Tanabata Festival, "
第三个加密给出了P的高位,选择Factoring with high bits known攻击 附上脚本,在sage里运行
1 2 3 4 5 6 7 8 9 10 11 12
p = 0xd6a35446aa682606213555b20b25ec4c1c7ab3347fa20de2cc26b0fcc10e7a48057e4fcb095e1eac71b4b16a6b021a9e656fef70000000000000000000000000 n = 0x72143b40dc0dc54bc0fd389680d49bfbec8ca9e81b872a700a7652e56b94533047f178d5e3bb7ccf1f8ebddf79f2a962f631da9a3adde261cb3c7094db9594d21898e9aa7fcd7e0d7713096b26c7d777600dd4ab0f97ff45e1883f4fc85e36895a2a7900e304142948a1a66963f952d073d40f267fd0f765d5b5f79e3e693787 kbits = 100 低位个数(使用时去除该中文) PR.<x> = PolynomialRing(Zmod(n)) f = x + p x0 = f.small_roots(X=2^kbits, beta=0.4)[0] print("x: %s" %hex(int(x0))) p = p+x0 print("p: ", hex(int(p))) assert n % p == 0 q = n/int(p) print("q: ", hex(int(q)))
$msg3=cow and bull woman\'s day, Qixi, etc., is a traditional festival among Chinese people.
最终解密
1 2 3 4 5 6
import hashlib answer='Tanabata Festival, also known as Qiqiao Festival, Qijie Festival, daughter\'s day, Qiqiao Festival, Qiniang society, Tanabata Festival, cow and bull woman\'s day, Qixi, etc., is a traditional festival among Chinese people.' m=hashlib.sha256() m.update(answer.encode('utf-8')) answer1=m.hexdigest() print(answer1)
<?php include('flag.php'); highlight_file(__FILE__); class YunBao{ public $admin; public $password; public function __construct($a,$p){ $this->admin=$a; $this->password = $p; } public functionlogin(){ return$this->admin===$this->password; } } $YunBao = unserialize($_GET['YunBao']); $YunBao->admin=md5(mt_rand()); if($YunBao->login()){ echo$flag;
这里直接引用
1 2 3 4 5 6 7 8 9 10 11 12
<?php class YunBao { public $admin = 1; public $password = '$this ->admin'; }