Tags: cryptography-rsa crypto
Rating:
In equation Sing ^ E % N = Pad we need to find E+N.
Note that E does not check and just use E=1.
Then N = Sign - Pad
Code:
```
#!/usr/bin/python
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5 as RSAsign
from Crypto.Hash import SHA
#from Util import PKCS1_pad as pad
def PKCS1_pad(data):
asn1 = "003021300906052b0e03021a05000414"
ans = asn1+data
n=len(ans)
padding = '0001'+'f'*(1024/4-n-4)
return int((padding + ans),16)
#from SECRET import flag
flag = "Local_Flag!"
import sys
def verify(s,m,n,e):
if pow(s,e,n) == pad(m):
return True
else:
return False
key = RSA.generate(1024)
message = "super important information for admin only"
h = SHA.new(message)
signer = RSAsign.new(key)
signature = signer.sign(h)
s = int(signature.encode("hex"),16)
print "Welcome to admin's music portal.\nTo verify that you are the owner of this service\nsend the public key which will verify the following signature :\n"
print "Message ->", message
print
print "Signature ->", signature.encode("hex")
print
sys.stdout.flush()
#n = long(raw_input("Enter n:"))
#e = long(raw_input("Enter e:"))
sm = long(raw_input("Enter s:"),16)
pm = pad(h.hexdigest())
e = 1L
n = sm-pm
print "\nN: ", n
print "\nE: ", e
sys.stdout.flush()
input_key = RSA.construct((n,e))
if verify(s,h.hexdigest(),n,e):
print flag
else:
print "Music is only for admin's eyes."
sys.stdout.flush()
```
Flag:
```
$ echo -n CTF{<REMOTED>} | openssl sha256
(stdin)= 93b7d01e2d60c22e5cc3033a86bc9ed577208139581bbae48397b2d656f285d6
```