No shot I would get this. This challenge is based on the Paillier cryptosystem, an additive homomorphic cryptosystem.
Paillier cryptosystem exploits the fact that certain discrete logarithms can be computed easily. Indeed, by binomial theorem:
which, under modulo
This is the crux of the challenge. Given the prime
and given the public key
Python Implementation:
xxxxxxxxxx
from pwn import *
import json
io = remote('socket.cryptohack.org', 13403)
q = io.recvline().decode().strip().split(": ")[1]
q = int(q[1:-1], 0)
# Insane solution
g = q + 1
n = q ** 2
io.recvuntil(b"Send integers (g,n) such that pow(g,q,n) = 1: ")
to_send = dict()
to_send['g'] = hex(g)
to_send['n'] = hex(n)
io.sendline(json.dumps(to_send).encode())
pub_key = io.recvline().decode().strip().split(": ")[1]
pub_key = int(pub_key[1:-1], 0)
x = (pub_key - 1) // q
to_send = dict()
to_send['x'] = hex(x)
io.sendline(json.dumps(to_send).encode())
io.interactive()
This provides some new light on some group that we can easily compute the discrete log. I have a huge tunnel vision on Euler's theorem, and thought that we are forced to do this under some group of order