#!/usr/bin/env python
from Crypto.PublicKey import RSA
from pwn import *


#sh = process("./rsa_machine_public.py")
#Connect to remote server
sh = remote('rsamachine.wpictf.xyz', 31337)
pubKey = RSA.importKey(sh.recv())
mod = pubKey.n
exp = pubKey.e
 
#m_1
payload = 'sign '+ '7'
print(payload)
sh.sendline(payload)
part1 = int(sh.recv())

#m_2
payload = 'sign '+'\x01\xe1CG\xae0Q'
print(payload)
sh.sendline(payload)
part2 = int(sh.recv())

#getflag command with the forged signature
payload = "getflag " + str((part1*part2) % mod)
sh.sendline(payload)

#print the flag
print(sh.recv())

