- Intro
- Classical Pre-Processing
- Quantum Operations
- Classical Post Processing
- Default Example
- References
A semiprime
a^(b+r) ≡ a^b (mod N)
Setting
a^r ≡ 1 (mod N)
a^r - 1 ≡ 0 (mod N)
(a^(r/2))^2 - 1 ≡ 0 (mod N)
(a^(r/2) - 1)(a^(r/2) + 1) ≡ 0 (mod N)
Hence the two products in the last line divide
RSA encryption involves the generation of a public semiprime key, hence Shor's algorithm can be utilised to find the private decryption key to decrypt the corresponding messages. Classical computers would take billions of years to break RSA-2048, but a quantum computer would take months!
There is no point running Shor's algorithm if
When we randomly pick a smaller integer
If these conditions are satisfied, then we continue to the quantum part.
Two registers are used.
The first will be of size |ψ0⟩ = |0⟩|0⟩.
Hadamard operators are used to create a superposition of all possible states, with equal amplitudes, for the first register only. A Hadamard matrix for one qubit is given as:
H = (1/√2) * [ [1, 1],
[1, -1] ]
The Hadamard matrices are then applied to all qubits in the first register by iterating numpy.kron() - which calculates the Kronecker product of two matrices.
The full Hadamard matrix is then multiplied with the identity matrix (for the second register), also by using the Kronecker product.
Applying this to the full register gives:
|ψ1⟩ = (H^{⊗n} ⊗ I_{2^n})|ψ0⟩ = (1/√(2^n)) ∑_x |x⟩|0⟩
A unitary matrix |ψ1⟩ above gives:
|ψ2⟩ = U|ψ1⟩ = (1/√(2^n)) ∑_x |x⟩|a^x mod N⟩
This leaves the first register unchanged, but entangles it with the second - encoding periodicity.
An IQFT matrix is constructed to make the amplitudes of the first register states periodic.
QFT^{-1}|x⟩ = (1/√(2^n)) ∑_k exp(2πi * x * k / 2^n)|k⟩
Peaks in probability form near states with index
In a real implementation of Shor's algorithm using quantum hardware, a measurement of the first register would have to be taken for a chance of finding
In this project, the first register state probabilities are plotted against the state index to display the period.
find_period.py then takes these probabilities and finds
We also time the algorithm for different pairs of
The simplest example is factoring
7^0 ≡ 1 (mod 15)
7^1 ≡ 7 (mod 15)
7^2 ≡ 4 (mod 15)
7^3 ≡ 13 (mod 15)
7^4 ≡ 1 (mod 15)
7^5 ≡ 7 (mod 15)
⋮
(We can see that
The smallest power of
Applying a Hadamard operator on a qubit
H|0⟩ = (1/√2) * (|0⟩ + |1⟩)
and applying Hadamard operators on all qubits in the first register:
(H_1 ⊗ H_2 ⊗ H_3 ⊗ H_4)|0⟩ = (1 / 4) * (|0⟩ + |1⟩ + ... + |15⟩)
(However, in the file quantum_part.py, H_1 ⊗ H_2 ⊗ ... ⊗ H_n is multiplied with the identity
Writing the oracle unitary operator as:
U = ∑_x ∑_y |x⟩|(y + a^x) mod N⟩⟨y|⟨x|
where both
|0⟩|y⟩ → |0⟩|y + 1⟩
|1⟩|y⟩ → |1⟩|y + 7⟩
⋮
|15⟩|y⟩ → |15⟩|y + 13⟩
The non-zero elements
j = x * 16 + ((y + 7^x) mod 15)
k = x * 16 + y
This example's elements
(1 / 4) * exp(2πi * j * k / 16)
Applying this matrix increases the probabilities of measuring the states
Post-processing checks will be passed, so there is no need to restart the algorithm with a different
(a^(r/2)) + 1 = (7^(4 / 2)) + 1 = 4 + 1 ≡ 5 (mod 15)
(a^(r/2)) - 1 = (7^(4 / 2)) - 1 = 4 - 1 ≡ 3 (mod 15)
such that
📘 Author: Sid Richards (SidRichardsQuantum)
LinkedIn: https://www.linkedin.com/in/sid-richards-21374b30b/
This project is licensed under the MIT License - see the LICENSE file for details.