From 9b5c6c82bc7080851d1fcef0ce5d041004570c90 Mon Sep 17 00:00:00 2001 From: jude Date: Mon, 29 May 2023 17:13:54 +0100 Subject: [PATCH] Lattices with transforms --- .idea/watcherTasks.xml | 25 ++++++++++ components.py | 14 ++++++ consts.py | 3 ++ main.py | 104 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 .idea/watcherTasks.xml create mode 100644 components.py create mode 100644 consts.py diff --git a/.idea/watcherTasks.xml b/.idea/watcherTasks.xml new file mode 100644 index 0000000..07e3ccc --- /dev/null +++ b/.idea/watcherTasks.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file diff --git a/components.py b/components.py new file mode 100644 index 0000000..b5f7f0a --- /dev/null +++ b/components.py @@ -0,0 +1,14 @@ +from manim import * +from consts import * + + +class TitledScene(Scene): + def add_title(self, title_text): + title = Tex(title_text, font_size=LARGE_FONT) + title.set_z_index(100) + title.to_edge(LEFT + UP) + + self.add(title) + self.play(Write(title)) + + return title diff --git a/consts.py b/consts.py new file mode 100644 index 0000000..a268d3e --- /dev/null +++ b/consts.py @@ -0,0 +1,3 @@ +LARGE_FONT = 48 +MEDIUM_FONT = 40 +SMALL_FONT = 32 diff --git a/main.py b/main.py index e69de29..5e7a1de 100644 --- a/main.py +++ b/main.py @@ -0,0 +1,104 @@ +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()