Grover’s Quantum Algorithm
Introduction
With the 1996 paper “A fast quantum mechanical algorithm for database search”, the Indian-American computer scientist Lov K. Grover helped highlight the non-negligible impact of quantum computing on the cryptographic systems currently in use.
Grover’s work concerns the problem of searching an unstructured database, i.e., a database lacking any ordering that could facilitate the search operation.
To understand the contribution of Grover’s algorithm, let us consider a simple example. Take a standard telephone directory in which names are listed in alphabetical order, each associated with a corresponding phone number.
Suppose, however, that one needs to perform a reverse lookup and therefore has a given phone number whose owner must be identified.
A classical approach to solving this problem consists of scanning the directory and checking the phone numbers one by one until the desired one is found, thereby identifying the associated name. Consequently, in the worst case, identifying the owner requires checking all the numbers in the directory except the last one.
By contrast, using Grover’s algorithm, a quantum computer would solve the same instance with a much smaller number of “quantum checks” compared to the classical case. In particular, one speaks of a quadratic speed-up with respect to the classical approach. This means that, given a search problem requiring
checks in the classical case, the quantum case using Grover’s algorithm requires only about
quantum checks.
Returning to the previous example, if the telephone directory consisted of 10000 entries, the classical approach would require 9999 checks in the worst case, whereas the quantum approach would require fewer than 100.
If a quantum computer with adequate characteristics were to be realized, the most relevant security implications of Grover’s result would arise in the context of symmetric cryptography currently in use.
For example, consider the AES (Advanced Encryption Standard) encryption scheme with a cryptographic key
of length 128 bits, and assume that an attacker knows some plaintext–ciphertext pairs and aims to find the key such that, for each known pair, the corresponding ciphertext can be obtained from the plaintext and vice versa.
At the state of the art, no attack is known that performs significantly better than exhaustive search for key recovery[1].
In the classical case, exhaustive search would require approximately
calls to the oracle[2]
to determine
, whereas in the quantum case Grover’s algorithm would invoke the oracle
approximately
times, with a success probability very close to 1.
It is often stated in common narratives that Grover’s search algorithm “halves” the security of modern symmetric cryptography. This halving refers to the bit length of the key involved. For instance, breaking AES with a
-bit key using Grover’s algorithm requires a number of quantum oracle invocations comparable to the number of classical oracle invocations needed to break AES with a
-bit key via exhaustive search.
As a consequence, it is reasonable to expect that, in order to restore the security of symmetric schemes in light of developments in quantum computing, it would suffice to double the cryptographic key size in bits. However, this would be a particularly conservative choice in practice, since the effective halving of security can only be considered partial, for at least two reasons.
The first reason is the difficulty of precisely determining the computational cost of executing
, which is generally believed to be higher than that of
[3].
The second aspect to consider is the impossibility of efficiently parallelizing the quantum search algorithm, which would therefore typically be executed on a single quantum processor, whereas the computational burden of exhaustive search can be distributed across multiple devices operating in parallel.
The following sections are devoted to a technical description of Grover’s algorithm and the corresponding quantum circuit. To fully understand the discussion, the reader is advised to review the concepts introduced in the previous article.
Qubits as Vectors
In order to interpret the rationale underlying Grover’s work, it is useful to review the definition of qubits in vectorial terms.
Let
be the
-dimensional complex vector space equipped with the usual inner product. Each
-qubit is associated with a unit-norm vector in this space.
In particular, vectors corresponding to qubits of the form
are called basis vectors.
As illustrative examples, consider the cases
and
. For
:
![Rendered by QuickLaTeX.com \[ \begin{aligned} \text{1-qubit basis states: } | & 0\rangle \longleftrightarrow \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \qquad |1\rangle \longleftrightarrow \begin{pmatrix} 0 \\ 1 \end{pmatrix}, \\ \text{Generic 1-qubit: } | & \psi\rangle = \alpha |0\rangle + \beta |1\rangle \longleftrightarrow \begin{pmatrix} \alpha \\ \beta \end{pmatrix}. \end{aligned} \]](https://www.telsy.com/wp-content/ql-cache/quicklatex.com-96f114eb4a04e04afeb110ed03992b5b_l3.png)
For
:
![Rendered by QuickLaTeX.com \[\begin{aligned} \text{2-qubit basis states: }| & 00\rangle \longleftrightarrow \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \end{pmatrix}, \qquad |01\rangle \longleftrightarrow \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix}, \qquad |10\rangle \longleftrightarrow \begin{pmatrix} 0 \\ 0 \\ 1 \\ 0 \end{pmatrix}, \qquad |11\rangle \longleftrightarrow \begin{pmatrix} 0 \\ 0 \\ 0 \\ 1 \end{pmatrix}, \\ \text{Generic 2-qubit: }| & \psi\rangle = \alpha |00\rangle + \beta |01\rangle +\gamma |10\rangle + \delta |11\rangle\longleftrightarrow \begin{pmatrix} \alpha \\ \beta \\ \gamma \\ \delta \end{pmatrix}. \end{aligned}\end{tiny} \]](https://www.telsy.com/wp-content/ql-cache/quicklatex.com-490eb43592afc8f55179be7326d6e476_l3.png)
Grover Circuit
In a numerical formulation of Grover’s search algorithm, without loss of generality, one may consider searching over the set of the first
natural numbers, with
, whose binary representations are:
![Rendered by QuickLaTeX.com \[ \begin{aligned} 0 & \leftrightarrow 0\dots 000 \\ 1 & \leftrightarrow 0\dots 001 \\ 2 & \leftrightarrow 0\dots 010 \\ \vdots & \\ N-1 & \leftrightarrow \underbrace{1\dots 111}_{n} \end{aligned} \]](https://www.telsy.com/wp-content/ql-cache/quicklatex.com-f46b9a7d031e4957a87179a2dfe05a61_l3.png)
The fact that only a particular
satisfies a given condition can be captured by defining the following function
, which outputs
if the input is
, and 0 otherwise.
![Rendered by QuickLaTeX.com \[\begin{aligned} f\colon {0,1}^n & \longrightarrow {0,1} \\ a & \longmapsto 1 \\ x (\neq a) & \longmapsto 0 \end{aligned}\]](https://www.telsy.com/wp-content/ql-cache/quicklatex.com-6319a8db82932441876575bf0113fafe_l3.png)
It is assumed that access to the function is provided through the oracle
, meaning that
is not known explicitly, but given
, the value
can be obtained.
In the absence of additional information about the distribution of the integers between
and
with respect to
, a classical computer can only proceed via exhaustive search, applying the oracle to different elements of
until
is found.
To achieve a success probability of
, the oracle must be queried on
distinct integers. In particular, a probability greater than
of identifying
is achieved by performing at least
oracle calls, while in the worst case, for a deterministic answer, the number of oracle invocations is
.
Since this number grows linearly with
, the oracle complexity is denoted asymptotically as
.
Under the same assumptions on the database, Grover’s 1996 work proposes a quantum algorithm capable of solving the search problem with probability very close to
, using approximately
calls to the quantum oracle
for large
, asymptotically
. Since the number of oracle calls scales linearly with
, this constitutes a quadratic speed-up over the classical exhaustive search algorithm.
More precisely, recall the action of
on a register of
qubits.
![]()
Given the function
defined above, consider the application of
to the
-qubit state
[4], where
.
![]()
In this form,
can be interpreted as a gate
acting only on the first
qubits as
![]()
Given a generic
-qubit state,
flips the sign of the component along
while leaving unchanged the component orthogonal to
.
Given the uniform superposition[5]
![]()
one defines, analogously to
, the transformation
, which acts on a generic
-qubit by fixing the component along
and flipping the sign of the component orthogonal to
.
The repeated successive application of the transformations
and
to the state
enables Grover’s algorithm to determine
in
steps. Below, the corresponding circuit and the proof of correctness are presented.

The first step consists in applying the Hadamard gate
to the state
. This places the first
qubits into the uniform superposition
, allowing the last qubit to be subsequently ignored and regarded as an ancillary qubit, in light of the previous observation regarding
.
Next, since the action of
and
on the states
and
yields linear combinations of these two states with real coefficients
![Rendered by QuickLaTeX.com \[\begin{aligned} & V_f|a\rangle=-|a\rangle, & & V_f|\phi\rangle=|\phi\rangle-\frac{2}{2^{\frac{n}{2}}}|a\rangle, \\\ & W|a\rangle = \frac{2}{2^{\frac{n}{2}}}|\phi\rangle-|a\rangle, & & W|\phi\rangle=|\phi\rangle, \end{aligned} \]](https://www.telsy.com/wp-content/ql-cache/quicklatex.com-1af4f91f7708e80bf1982cddeb81efa7_l3.png)
the analysis can be restricted to the real plane spanned by
and
.

In this plane,
reduces to a reflection about
, where
denotes the vector orthogonal to
that is “close” to
, while
reduces to a reflection about
. For sufficiently large
, the angle
between
and
can be approximated using
, since[6]
![]()
The combination of the reflections
and
results in a counterclockwise rotation of all qubits in the described plane by an angle
. In particular, the figure illustrates the action on the state
.

By repeating this operation
times, so as to traverse the entire arc from
to
, one obtains a quantum state which, upon measurement, collapses to
with probability very close to
. For completeness,
is obtained by solving the equation
![]()
from which
is the integer closest to the real number
.
[1] The best known attack against AES is the biclique attack, which provides a speed-up of approximately a factor
compared to exhaustive search.
[2] The oracle of a function
is a mechanism that allows one to obtain the evaluation of
on a given input without explicitly knowing the definition of
. In this case, the oracle returns a positive answer if and only if the key is the correct one. The classical oracle is denoted by
, while the quantum oracle is denoted by
.
[3] Note that the actual total cost is given by the product of the number of oracle executions and the cost of a single oracle execution.
[4] Recall that
![]()
[5] Superposition of all the considered basis states with the same real coefficient and, therefore, with the same probability.
[6] Note that the expression
denotes the inner product between
and
.
This article is part of a series of contributions by the Telsy Cryptography Research Group dedicated to quantum computing and its implications for cryptography. For other articles, please refer to the index of the section.
For other articles related to quantum and cryptography, please refer to the relevant categories in the blog.
The authors
Veronica Cristiano, a bachelor’s degree in Mathematics from the University of Pisa and a master’s degree in Mathematics with a specialization in Cryptography at the University of Trento, joined the Telsy Cryptography research group in mid-2021.
Francesco Stocco, a master’s degree in Mathematics at the University of Padua and the Université de Bordeaux attending the course of study “Algebra Geometry And Number Theory” (ALGANT), joined the Telsy research group in Cryptography at end of 2020 focusing in particular on issues related to quantum technologies.