題目來源: 2019_Redhat
題目描述: 粗心的Alice在製作密碼的時候,把明文留下來,聰明的你能快速找出來嗎?
題目附件: 附件1
1、 附件1
2、解壓後
3、選中「task.py」—>開啟
4、可直接找到flag
#!/usr/bin/env python3
from Crypto.Util import number
from Crypto.PublicKey import RSA
from hashlib import sha256
import json
#from secret import msg
msg = ‘Hahaha, Hastad’s method don’t work on this. Flag is flag{fa0f8335-ae80-448e-a329-6fb69048aae4}.’
assert len(msg) == 95
Usernames = [‘Alice’, ‘Bob’, ‘Carol’, ‘Dan’, ‘Erin’]
N = [ ( number.getPrime(1024) * number.getPrime(1024) ) for _ in range(4) ]
PKs = [ RSA.construct( (N[0], 3) ), RSA.construct( (N[1], 3) ), RSA.construct( (N[2], 5) ), RSA.construct( (N[3], 5) ) ]
for i in range(4):
name = Usernames[i+1]
open(name+‘Public.pem’, ‘wb’).write( PKs[i].exportKey(‘PEM’) )
data = {‘from’: sha256( b’Alice’ ).hexdigest(),
‘to’ : sha256( name.encode() ).hexdigest(),
‘msg’ : msg
}
data = json.dumps(data, sort_keys=True)
m = number.bytes_to_long( data.encode() )
cipher = pow(m, PKs[i].e, PKs[i].n)
open(name+‘Cipher.enc’, ‘wb’).write( number.long_to_bytes(cipher) )
5、OK
flag{fa0f8335-ae80-448e-a329-6fb69048aae4}