Shor’s algorithm#

In the realm of quantum computing, where classical limitations are challenged and new horizons are explored, Shor’s Algorithm stands as a testament to the transformative potential of quantum mechanics in the field of cryptography. Developed by mathematician Peter Shor in 1994, this groundbreaking algorithm has the power to revolutionize the world of cryptography by efficiently factoring large numbers—once considered an insurmountable task for classical computers.

Qrisp provides a dead simple interface to integer factorization using your own backend. For details how this algorithm is implemented, please check the Shor tutorial.

shors_alg(N, inpl_adder=None, mes_kwargs={})[source]#

Performs Shor’s factorization algorithm on a given integer N. The adder used for factorization can be customized. To learn more about this feature, please read QuantumModulus


The integer to be factored.

inpl_addercallable, optional

A function that performs in-place addition. The default is None.

mes_kwargsdict, optional

A dictionary of keyword arguments for get_measurement. This especially allows you to specify an execution backend. The default is {}.


A factor of N.


We factor 65:

>>> from qrisp.shor import shors_alg
>>> shors_alg(65)

Cryptography tools#

These tools can be utilized to spy on your enemies.

rsa_encrypt(p, q, e, message_int)

Encrypts an integer using the private keys \(p\), \(q\) and a public key \(e\).

rsa_decrypt(ciphertext, e, N[, backend])

Decrypts an integer using factorization powered by Shor's algorithm.

rsa_encrypt_string(p, q, e, message)

Encrypts an arbitrary Python string using RSA.

rsa_decrypt_string(e, N, ciphertext[, backend])

Decrypts a bitstring into a human readable string.