← Back to Writeups
CUSTOMEasyCrypto

Tooled RSA

XESXOR9/10/20261 min read
#crypto#custom#easy#factordb_lookup#standard_rsa_decrypt

Tooled RSA

Platform: spbctf | Category: Crypto | Type: Challenge | Difficulty: Easy | OS: NA | Author: XESXOR | Date: 2026-03-09 | Status: Solved Techniques: factordb_lookup, standard_rsa_decrypt

Summary

Task: Standard RSA encryption with n, e, c given. Solution: Check factordb.com for known factorization of n, then perform standard RSA decryption.

Tooled RSA — CryptoKids 2.0

Description

Standard RSA encryption. Given n, e, c. Need to decrypt.

Analysis

  • Standard RSA setup with n, e, c
  • The modulus n is already factored in factordb.com
  • Once p and q are known, standard RSA decryption applies
  • Task name "Tooled" hints at using existing tools/databases

Solution

Check factordb.com for known factorization of n. If found, compute d and decrypt.

python
#!/usr/bin/env python3
# RSA decryption with factordb lookup

from factordb.factordb import FactorDB
# pip install factordb-python
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

def decrypt_rsa(n, e, c, p, q):
    """Standard RSA decryption"""
    phi = (p - 1) * (q - 1)
    d = pow(e, -1, phi)
    m = pow(c, d, n)
    return m

# Given parameters
n = ...  # RSA modulus
e = 65537
c = ...  # ciphertext

# Check factordb
f = FactorDB(n)
f.connect()
factors = f.get_factor_list()

if len(factors) == 2:
    p, q = factors
    print(f"Found factors!")
    print(f"p = {p}")
    print(f"q = {q}")
    
    # Decrypt
    m = decrypt_rsa(n, e, c, p, q)
    
    # Convert to bytes
    flag = bytes.fromhex(hex(m)[2:])
    print(f"Flag: {flag.decode()}")
else:
    print(f"Factorization status: {f.get_status()}")
    print(f"Factors: {factors}")
‍​‌‌​​‌​​​‌‌​​‌​​​​‌‌​‌​​​​‌‌‌​​‌​​‌‌​​​‌​​‌‌‌​​​​​‌‌​‌‌​​​‌‌​​​​‍

# Alternative: use rsatool
# rsatool -f PEM -o key.pem -p <p> -q <q>
# openssl rsautl -decrypt -inkey key.pem -in ciphertext.bin

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