I have this as my minor project and plan to use Shor' Algorithm for factorization to figure out the $p$ and $q$ factors for cracking. Although I understand the theoretical part, I am having some problems in implementing it.

  • 5
    $\begingroup$ Could you be more specific about what problem you're encountering? As stated, your question reads an awful lot like "Do my project for me". $\endgroup$ Commented Oct 12, 2018 at 15:19
  • $\begingroup$ Sorry for being quite vague. I actually have studied a bit and am not at all asking for spoon feeding. I just have problem in starting the quantum part of this problem, as to how to approach this step 2 of the article medium.com/quantum-bits/… $\endgroup$ Commented Oct 12, 2018 at 16:08
  • 2
    $\begingroup$ @Anshuman It would be great if you could edit your question accordingly to make clear what precisely you are looking for! $\endgroup$ Commented Oct 12, 2018 at 16:11
  • $\begingroup$ Welcome to Quantum Computing SE! As mentioned in the above comments, it's rather difficult to figure out exactly what your problem(s) is/are, so it's going to be particularly hard to provide an adequate answer, so I've put the question on hold to help prevent answers being less helpful than they could otherwise be. If you can identify a specific problem you've got, please edit the question and that will automatically put the question in a reopen review queue. If you've got several specific problems, you're very welcome to make multiple posts $\endgroup$
    – Mithrandir24601
    Commented Oct 12, 2018 at 19:33

1 Answer 1


As Craig Gidney has said in the first comment, you will have to give us further instructions about what specific part of Shor's algorithm you need assistance with, since asking us to work through an entire 32-bit example would be considered "doing your homework for you".

However I see no harm in helping you with the non-quantum part of it, and I think this will be useful for other users who want to learn RSA without reading a rather large Wikipedia page or tutorial which is catered more towards pure math students.

In RSA you will have a public key which contains two numbers: $n$ and $e$. You need to factor $n$ into $p\times q$. Once you have $p$ and $q$ you can calculate Carmichael's totient function of $n$, which is called $\lambda$ and is equal to the lowest common multiple of $p-1$ and $q-1$.

The "private key" $d$ can be found by solving: $e\times d = 1\hspace{-3mm}\mod\hspace{-1mm} \lambda$.

You can now crack the code $c$ to get the original message $m$:

$m=c^d \hspace{-3mm}\mod \hspace{-1mm}n$.

  • 2
    $\begingroup$ The part that I explained was taught in our first year undergraduate algebra class at University of Waterloo, also it's on Wikipedia and easily accessible. How to break RSA is public knowledge. Anyone who can't figure out how to break RSA by reading Wikipedia, is definitely not going to have the mathematics and programming skills to factor RSA-2048. Even RSA-768 took 5 years on an HPC cluster, running massively parallel codes using MPI and written by the groups of Zimmerman and Lenstra, who know the number theory inside out. I don't think I'm helping anyone crack codes! $\endgroup$ Commented Oct 14, 2018 at 14:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.