Skip to content

Instantly share code, notes, and snippets.

@mimoo
Last active March 29, 2016 17:37
Show Gist options
  • Save mimoo/c2a927be6944667ea25a7074e9cb784c to your computer and use it in GitHub Desktop.
Save mimoo/c2a927be6944667ea25a7074e9cb784c to your computer and use it in GitHub Desktop.
contributions for Tikz for cryptographers
\begin{tikzpicture}
\begin{scope}[scale=.28,local bounding box=scope1]
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-1,0);
\coordinate (XAxisMax) at (10,0);
\coordinate (YAxisMin) at (0,-1);
\coordinate (YAxisMax) at (0,10);
\draw [thin, black!40, <->] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, black!40,<->] (YAxisMin) -- (YAxisMax);% Draw y axis
%\draw[style=help lines,dashed,black!20] (-5,-5) grid[step=1cm] (5,5);
% basis vectors
\draw [->] (Origin) -- (4,1);
\draw [->] (Origin) -- (1,3);
% explanation
\node[right] at (-7, 9) {\small{non-lattice vector}};
\draw[->, black!50] (-3, 8) -- (6,6.25);
\node[right] at (-7, 4) {\small{basis vectors}};
\draw[->, black!50] (-5, 3) -- (-1, 2);
% our little node
\node[shape=circle,fill=purple,scale=0.4] at (6.7,6.25){};
\node[shape=circle,draw=purple,fill=none,scale=0.8] at (6.7,6.25){};
\end{scope}
\begin{scope}[scale=.28,shift={(13,0)}]
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-1,0);
\coordinate (XAxisMax) at (10,0);
\coordinate (YAxisMin) at (0,-1);
\coordinate (YAxisMax) at (0,10);
\draw [thin, black!40, <->] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, black!40,<->] (YAxisMin) -- (YAxisMax);% Draw y axis
%\draw[style=help lines,dashed,black!20] (-5,-5) grid[step=1cm] (5,5);
% basis vectors
\draw [->] (Origin) -- (4,1);
\draw [->] (Origin) -- (1,3);
% extended basis vectors
\draw [black!40] (4,1) -- (5,1.25);
\draw [black!40] (1,3) -- (1.6,5);
\draw [black!40] (5.1,1.25) -- (6.7,6.25);
\draw [black!40] (1.6,5) -- (6.7,6.25);
%\draw [black!40] (4,1) -- (5,4);
%\draw [black!40] (1,3) -- (5,4);
% our little node
\node[shape=circle,fill=purple,scale=0.4] at (6.7,6.25){};
\end{scope}
\begin{scope}[scale=.28,shift={(26,0)}]
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-1,0);
\coordinate (XAxisMax) at (10,0);
\coordinate (YAxisMin) at (0,-1);
\coordinate (YAxisMax) at (0,10);
\draw [thin, black!40, <->] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, black!40,<->] (YAxisMin) -- (YAxisMax);% Draw y axis
%\draw[style=help lines,dashed,black!20] (-5,-5) grid[step=1cm] (5,5);
% basis vectors
\draw (Origin) -- (4,1);
\draw (Origin) -- (1,3);
% extended basis vectors
\draw [black!40] (4,1) -- (5,4);
\draw [black!40] (1,3) -- (5,4);
% our little node
\node[shape=circle,fill=purple!60,scale=0.4] at (6.7,6.25){};
% our new little node :)
\node[shape=circle,fill=purple,scale=0.4] at (5,4){};
\node[shape=circle,fill=none,draw=purple,scale=0.8] at (5,4){};
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\tikzstyle{every node}=[draw, shape=circle, ultra thick];
\node (D) at (2,2) {Alice};
\node (A) at (0,0) {David};
\node (B) at (2,0) {Bob};
\node (C) at (4,0) {Charles};
\tikzstyle{every node}=[draw,shape=rectangle,solid,fill=white];
\draw [->,dashed] (D) -- (A) node [above right=10mm] {$m^3 \pmod{N_1}$};
\draw [->,dashed] (D) -- (B) node [above=15mm] {$m^3 \pmod{N_2}$};
\draw [->,dashed] (D) -- (C) node [above left=10mm] {$m^3 \pmod{N_3}$};
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}[scale=.55,local bounding box=scope1]
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-5,0);
\coordinate (XAxisMax) at (5,0);
\coordinate (YAxisMin) at (0,-5);
\coordinate (YAxisMax) at (0,5);
\draw [thin, black!40, <->] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, black!40,<->] (YAxisMin) -- (YAxisMax);% Draw y axis
%\draw[style=help lines,dashed,black!20] (-5,-5) grid[step=1cm] (5,5);
\begin{scope}
\clip (-5,-5) rectangle (5,5); % Clips the picture...
\pgftransformcm{1}{0.6}{0.7}{1}{\pgfpoint{0cm}{0cm}}
% setup the nodes
\foreach \x in {-15,...,15}
\foreach \y in {-15,...,15}
{
\node[shape=circle,fill=black!45,scale=0.35] (\x-\y) at (2*\x,\y+3){};
}
\end{scope}
% our little node
\node[shape=circle,fill=purple,scale=0.4] at (2.5,3.4){};
\node[shape=circle,draw=purple,fill=none,scale=0.8] at (2.5,3.4){};
\end{scope}
\begin{scope}[scale=.55,shift={(12,0)}]
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-5,0);
\coordinate (XAxisMax) at (5,0);
\coordinate (YAxisMin) at (0,-5);
\coordinate (YAxisMax) at (0,5);
\draw [thin, black!40, <->] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, black!40,<->] (YAxisMin) -- (YAxisMax);% Draw y axis
%\draw[style=help lines,dashed,black!20] (-5,-5) grid[step=1cm] (5,5);
\begin{scope}
\clip (-5,-5) rectangle (5,5); % Clips the picture...
\pgftransformcm{1}{0.6}{0.7}{1}{\pgfpoint{0cm}{0cm}}
% setup the nodes
\foreach \x in {-15,...,15}
\foreach \y in {-15,...,15}
{
\node[shape=circle,fill=black!45,scale=0.35] (\x-\y) at (2*\x,\y+3){};
}
\end{scope}
% our little node
\node[shape=circle,fill=purple!60,scale=0.4] at (2.5,3.4){};
\node[shape=circle,fill=purple,scale=0.4] at (2.1,3){};
\node[shape=circle,fill=none,draw=purple,scale=0.8] at (2.1,3){};
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\node [above] at (5,10) {\textbf{random basis}};
\node [above] at (18,10) {\textbf{reduced basis}};
\draw [lightgray] [<->] (0,5) -- (10,5);
\draw [lightgray] [<->] (5,10) -- (5,0);
\draw [fill,purple,opacity=.4] (9,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (7,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (8,2) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (9,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (5,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (6,2) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (7,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (8,4) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (9,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (3,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (4,2) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (5,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (6,4) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (7,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (8,6) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (9,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (1,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (2,2) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (3,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (4,4) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (5,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (6,6) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (7,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (8,8) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (9,9) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (1,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (2,4) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (3,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (4,6) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (5,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (6,8) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (7,9) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (1,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (2,6) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (3,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (4,8) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (5,9) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (1,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (2,8) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (3,9) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (1,9) circle [radius=0.1];
%
\draw [thick,black] [->] (11,5) -- (12,5);
\node [above] at (11.5,5) {$_{LLL}$};
%
\draw [lightgray] [<->] (13,5) -- (23,5);
\draw [lightgray] [<->] (18,10) -- (18,0);
\draw [fill,purple,opacity=.4] (22,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (20,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (21,2) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (22,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (18,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (19,2) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (20,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (21,4) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (22,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (16,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (17,2) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (18,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (19,4) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (20,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (21,6) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (22,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (14,1) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (15,2) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (16,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (17,4) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (18,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (19,6) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (20,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (21,8) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (22,9) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (14,3) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (15,4) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (16,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (17,6) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (18,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (19,8) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (20,9) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (14,5) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (15,6) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (16,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (17,8) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (18,9) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (14,7) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (15,8) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (16,9) circle [radius=0.1];
\draw [fill,purple,opacity=.4] (14,9) circle [radius=0.1];
% vectors
\draw [thick,purple] [->] (5,5) -- (7, 9);
\draw [thick,purple] [->] (5,5) -- (6, 8);
\draw [thick,purple] [->] (18,5) -- (19, 4);
\draw [thick,purple] [->] (18,5) -- (19, 6);
\end{tikzpicture}
\begin{tikzpicture}
% main formula
\node[align=center] (main) {$y = g^x \pmod{p}$\\
$\varphi(p) = p-1 = p_1 \times \cdots \times p_k$};
% first line
\node (xmodp1) [below left=.9cm and -1.2cm of main, align=left] {$x \pmod{p_1}$};
\node (dots) [below=1.1cm of main, align=left] {$\cdots$};
\node (xmodpk) [below right=.9cm and -1.2cm of main, align=left] {$x \pmod{p_k}$};
% Pohlig Hellman
\node (PH) [above=.2cm of dots, align=left] {Pohlig-Hellman};
% arrows
\draw (main) edge[out=200,in=90,->] (xmodp1);
\draw (main) edge[out=340,in=90,->] (xmodpk);
% second line
\node (xmodpm1) [below=.9cm of dots, align=left] {$x \pmod{\varphi(p)}$};
% CRT
\node (CRT) [above=.2cm of xmodpm1, align=left] {CRT};
% arrows
\draw [->] (xmodp1) -- (xmodpm1);
\draw [->] (xmodpk) -- (xmodpm1);
\end{tikzpicture}
\begin{tikzpicture}
\begin{scope}[scale=.55,local bounding box=scope1]
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-5,0);
\coordinate (XAxisMax) at (5,0);
\coordinate (YAxisMin) at (0,-5);
\coordinate (YAxisMax) at (0,5);
\draw [thin, black!40, <->] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, black!40,<->] (YAxisMin) -- (YAxisMax);% Draw y axis
%\draw[style=help lines,dashed,black!20] (-5,-5) grid[step=1cm] (5,5);
\begin{scope}
\clip (-5,-5) rectangle (5,5); % Clips the picture...
\pgftransformcm{1}{0.6}{0.7}{1}{\pgfpoint{0cm}{0cm}}
% setup the nodes
\foreach \x in {-15,...,15}
\foreach \y in {-15,...,15}
{
\node[shape=circle,fill=black!45,scale=0.35] (\x-\y) at (2*\x,\y+3){};
}
\end{scope}
\end{scope}
\begin{scope}[scale=.55,shift={(12,0)}]
\coordinate (Origin) at (0,0);
\coordinate (XAxisMin) at (-5,0);
\coordinate (XAxisMax) at (5,0);
\coordinate (YAxisMin) at (0,-5);
\coordinate (YAxisMax) at (0,5);
\draw [thin, black!40, <->] (XAxisMin) -- (XAxisMax);% Draw x axis
\draw [thin, black!40,<->] (YAxisMin) -- (YAxisMax);% Draw y axis
\draw [thin, purple,->] (0,0) -- (-.5,.7);
%\draw[style=help lines,dashed,black!20] (-5,-5) grid[step=1cm] (5,5);
\begin{scope}
\clip (-5,-5) rectangle (5,5); % Clips the picture...
\pgftransformcm{1}{0.6}{0.7}{1}{\pgfpoint{0cm}{0cm}}
% setup the nodes
\foreach \x in {-15,...,15}
\foreach \y in {-15,...,15}
{
\node[shape=circle,fill=black!45,scale=0.35] (\x-\y) at (2*\x,\y+3){};
}
\end{scope}
% our little node
\node[shape=circle,fill=purple,scale=0.35] at (-.6,.8){};
\end{scope}
\end{tikzpicture}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment