PCAT - Mission Impossible
1 | Name: Mission Impossible |
Challenge source
1 | #!/usr/bin/env python3 |
Core idea
The service asks for P, Q, R, N such that:
isPrime(P),isPrime(Q),isPrime(R), andisPrime(N)are all true.N = P * Q * R.Nhas at least 1024 bits.
N is obviously composite, so the key is to make
N a strong pseudoprime for all hardcoded Miller-Rabin
bases.
Construction outline
Use an Arnault-style construction with:
P = a*k + 1Q = b*k + 1R = c*k + 1
Choose a, b, c as distinct primes with
a, b, c ≡ 1 (mod 8) (for base-2 behavior), e.g.
89, 113, 137.
To make (P-1), (Q-1), (R-1) divide (N-1),
solve the congruence system:
1 | k ≡ -(b+c)(bc)^(-1) (mod a) |
For odd MR bases B in {3,5,...,79}, force
k ≡ 0 (mod B). Also force k ≡ 2 (mod 4) so
P, Q, R ≡ 3 (mod 4).
Then scan k until P, Q, R are all truly
prime (with a strong primality test like
sympy.isprime).
Solver script
1 | #!/usr/bin/env python3 |
Ciphertext from remote
1 | 21903103496980081373563573693903562346746553643549818726007975948477827819459765088909748053913796144132553228584337940471254732244734196780412249598279393335004210910953390996721397236654824645841526330517109905833017093822718222876587329963794042086917871402474385749212962074053842003782042533173326441388721313429460738550791493248565473365397568505962364729491646535933145902419195195919991941091 |
RSA decryption (3-prime)
Once P, Q, R are known, decrypt like standard RSA:
phi(N) = (P-1)(Q-1)(R-1)d = e^(-1) mod phi(N)withe = 65537m = c^d mod N
1 | def decrypt(p, q, r, c): |