from
Crypto.PublicKey
import
RSA
from
Crypto.Signature
import
PKCS1_v1_5 as RSAsign
from
Crypto.
Hash
import
SHA
import
sys
import
binascii
def
pad(data):
asn1
=
b
'3021300906052b0e03021a05000414'
ans
=
asn1
+
data.encode(
'ascii'
)
n
=
len
(ans)
return
int
((b
'0001'
+
b
"ff"
*
(
1024
/
/
8
-
n
/
/
2
-
3
)
+
b
'00'
+
ans),
16
)
flag
=
b
"CTF{cryp70_5ur3_15_w13rd}"
def
verify(s,m,n,e):
if
pow
(s,e,n)
=
=
pad(m):
return
True
else
:
return
False
key
=
RSA.generate(
1024
)
message
=
b
"super important information for admin only"
h
=
SHA.new(message)
signer
=
RSAsign.new(key)
signature
=
signer.sign(h)
s
=
int
(binascii.hexlify(signature),
16
)
print
(
"Welcome to admin's music portal."
)
print
(
"To verify that you are the owner of this service"
)
print
(
"send the public key which will verify the following signature :"
)
print
(
"Message:"
, message)
print
(
"Signature:"
, signature)
sys.stdout.flush()
n
=
eval
(
input
(
"Enter n:"
))
e
=
eval
(
input
(
"Enter e:"
))
sys.stdout.flush()
try
:
input_key
=
RSA.construct((n,e))
except
ValueError:
print
(
'Value Error'
)
if
verify(s,h.hexdigest(),n,e):
print
(flag)
else
:
print
(b
"Music is only for admin's eyes."
)
sys.stdout.flush()