RSA tutorial
Cryptography · Mazala · Superior
Problem
Source code
Output
Reduce the Problem
Divide e and ϕ(n) by g:
e′=e/g
ϕ′=ϕ(n)/g
Compute the modular inverse of e′ modulo ϕ′:
d′=e′^(-1)mod ϕ′
Find gg-th Roots Modulo pp and qq:
Use the
nthroot_mod
function to compute:mp=nthroot_mod(c′,g,p) & mq=nthroot_mod(c′,g,q)
Combine Results Using CRT:
Use the Chinese Remainder Theorem (CRT) to combine mp and mq:
m=crt([p,q],[mp,mq])[0]
By reducing e and ϕ ( n ), we create new values e ′ , ϕ ′ , and c ′ that allow us to solve the problem despite the non-coprime issue.
What does nthroot_mod
do?
nthroot_mod
do?It Checks if a Solution Exists for flag and Solves.
Once m_p (solution modulo p) and m_q(solution modulo q) are found, the Chinese Remainder Theorem (CRT) combines them to get m.
Chinese Remainder Theorem
Combining m_p and m_q into one solution m.
Example
Example
Let’s say:
p=7, q=11, n=77.
e=16, c=23.
Compute ϕ(n)=(7−1)(11−1)=60.
Compute g=gcd(16,60)=4.
Reduce e′=16/4=4, ϕ′=60/4=15
Compute d′=4^{-1}mod 15=4(since 4⋅4=16≡1mod 15).
Compute c′=23^{4}mod 77.
Compute mp=nthroot_mod(c′,4,7) and mq=nthroot_mod(c′,4,11).
Combine mp and mq using CRT to get m mod 77.
Convert m to bytes to recover the flag.
Flag: mazala{m0dul4r_Square_r00t}
Last updated