Created
September 6, 2020 15:05
-
-
Save hyunsikjeong/e081094ccc982ae4e3c226581f63d0f4 to your computer and use it in GitHub Desktop.
padrsa solver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.Util.number import * | |
from binascii import unhexlify, hexlify | |
import gmpy2 | |
from pwn import * | |
def get_cube(): | |
sock = remote('crypto.kosenctf.com', 13001) | |
n = int(sock.recvuntil('\n')[3:-1].decode()) | |
def recv_msg(e): | |
sock.recvuntil("> ") | |
sock.sendline('1') | |
sock.recvuntil('e: ') | |
sock.sendline(str(e)) | |
recv = sock.recvuntil('\n') | |
c = bytes_to_long(unhexlify(recv[3:-1])) | |
return c | |
for i in range(64): | |
recv_msg(65537 - i) | |
c = recv_msg(3) | |
sock.close() | |
return n, c | |
n, c = get_cube() | |
while gmpy2.iroot(c, 3)[1] is False: | |
n2, c2 = get_cube() | |
c = (c * n2 * inverse(n2, n) + c2 * n * inverse(n, n2)) % (n * n2) | |
n = n * n2 | |
print(long_to_bytes(gmpy2.iroot(c, 3)[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment