← Back to Writeups
CUSTOMMediumCrypto

P*Q=ban

XESXOR9/2/20262 min read
#crypto#custom#medium#composite_rsa#factordb_lookup

P*Q=ban

Platform: CUSTOM | Category: Crypto | Type: Challenge | Difficulty: Medium | OS: N/A | **Author: XESXOR Techniques: composite_rsa, factordb_lookup

Summary

Walkthrough of the CUSTOM Crypto P*Q=ban. Task: RSA with very large modulus n (4119 bits). Solution: Lookup n in factordb.com to find composite (non-prime) factors p and q; the flag is one of the factors.

Description

RSA challenge with a very large modulus n (4119 bits). The title hints that the product p*q is "banned" or unusual.

Analysis

Analysis revealed:

  • n has a size of 4119 bits — unusually large for CTF
  • n is found in the factordb.com database
  • Factors p and q are composite numbers (not prime!)
  • p and q are very close to each other

This is a non-standard RSA challenge — normally p and q should be prime, but here they are composite. The answer is one of the factors. ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Solution

python
#!/usr/bin/env python3
import requests

def factordb_lookup(n):
    """Look up factorization in factordb.com"""
    url = f"http://factordb.com/api?query={n}"
    response = requests.get(url)
    data = response.json()
    
    status = data.get('status')
    # FF = fully factored, CF = composite with known factors
    # P = prime, C = composite (unknown factors)
    
    factors = data.get('factors', [])
    return status, factors

# Modulus from the challenge
n = ...  # very large number (4119 bits)
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

# Check in factordb
status, factors = factordb_lookup(n)
print(f"Status: {status}")
print(f"Factors: {factors}")

# Extract p and q
# factors usually in format [[factor1, power1], [factor2, power2]]
p = int(factors[0][0])
q = int(factors[1][0])

print(f"\np = {p}")
print(f"q = {q}")
print(f"p * q == n: {p * q == n}")

# Check if p and q are prime
from sympy import isprime
print(f"\np is prime: {isprime(p)}")
print(f"q is prime: {isprime(q)}")

# Flag is p or q
print(f"\nFlag (p): {p}")
print(f"Flag (q): {q}")

‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Alternatively, you can use the factordb.com web interface directly. ‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

Key Takeaways / Lessons

  • Mastering composite_rsa, factordb_lookup was key to this challenge.
  • Always check for common misconfigurations and verify assumptions.

Crafted by XESXOR Research • 2026-03-09 • CUSTOM • P*Q=ban • Difficulty: Medium