Goldreich-Goldwasser-Halevi/main.py
2023-05-29 17:13:54 +01:00

105 lines
3.1 KiB
Python

from consts import *
from components import *
import numpy as np
from manim import *
class Introduction(TitledScene):
def construct(self):
self.add_title("Goldreich--Goldwasser--Halevi")
self.wait()
text_1 = Tex(
r"""
\begin{itemize}
\item Lattice-based cryptosystem.
\item Devised in 1997 by Goldreich, Goldwasser, and Halevi.
\item Broken in 1999 by Nguyen.
\end{itemize}
""",
font_size=MEDIUM_FONT,
)
self.add(text_1)
self.play(Write(text_1, run_time=4.0))
self.wait()
class Premise(TitledScene):
def construct(self):
self.add_title("Lattices")
# A lattice is a subspace of a vector space that is constructed by taking integer multiples of some basis
# vectors.
# For example, take the real plane R2.
plane = NumberPlane(axis_config={"stroke_width": 0.0})
plane.set_z_index(-10)
plane.set_opacity(0.75)
dot = Dot(ORIGIN)
self.add(dot, plane)
self.play(Create(dot), Create(plane))
self.wait()
# We can construct the 2D grid of integers with the elementary basis
lattice_1 = VGroup()
arrow_1 = Arrow(ORIGIN, [1, 0, 0], buff=0)
arrow_2 = Arrow(ORIGIN, [0, 1, 0], buff=0)
self.play(Create(arrow_1), Create(arrow_2))
self.wait()
for i in range(-7, 8):
for j in range(-6, 7):
lattice_1.add(Dot([i, j, 0]))
self.play(Create(lattice_1))
# By moving these basis vectors but maintaining their linear independency, other lattices can be formed
self.play(
Transform(arrow_1, Arrow(ORIGIN, [1.5, 0, 0], buff=0)),
*[
Transform(
dot,
Dot(
dot.get_center()
* np.matrix([[1.5, 0, 0], [0, 1, 0], [0, 0, 1]])
),
)
for dot in lattice_1
]
)
self.wait()
self.play(
Transform(arrow_1, Arrow(ORIGIN, [1, -0.5, 0], buff=0)),
*[
Transform(
dot,
Dot(
dot.get_center()
* np.matrix([[2 / 3, 0, 0], [0, 1, 0], [0, 0, 1]])
* np.matrix([[1, -0.5, 0], [0, 1, 0], [0, 0, 1]])
),
)
for dot in lattice_1
]
)
self.wait()
self.play(
Transform(arrow_1, Arrow(ORIGIN, [1, -1, 0], buff=0)),
Transform(arrow_2, Arrow(ORIGIN, [1, 1, 0], buff=0)),
*[
Transform(
dot,
Dot(
dot.get_center()
* np.matrix([[1, 0.5, 0], [0, 1, 0], [0, 0, 1]])
* np.matrix([[1, -1, 0], [1, 1, 0], [0, 0, 1]])
),
)
for dot in lattice_1
]
)
self.wait()