How to draw a Caesar Cipher diagram with tikz?
Something like this?
\documentclass[tikz,border=2mm]{standalone}
\usepackage{libertine} % Change the font to your liking
\usepackage[T1]{fontenc}
\usetikzlibrary{decorations.text,arrows.meta,calc}
\tikzset{curved text/.style={decorate,
decoration={text effects along path,
text={#1}, text align=center,
text effects/.cd, text along path}}}
\begin{document}
\begin{tikzpicture}[x=1em,y=1em]
% set up
\pgfmathsetmacro\angdiv{360/26}
\pgfmathtruncatemacro\caeser{7} % Input Caeser shift here! (positive for clockwise)
\coordinate (n-0) at (90+\angdiv/2:7) {};
\coordinate (m-0) at (90-\caeser*\angdiv+\angdiv/2:5) {};
% draw Caeser diagram
\draw circle [radius=8] circle [radius=6.5] circle [radius=6] circle [radius=4.5]
\foreach \i in {0,...,25}{%
($({90-(\i-1/2)*\angdiv}:8)$) -- ($(({90-(\i-1/2)*\angdiv}:6.5)$)
($({90-(\i-1/2)*\angdiv}:4.5)$) -- ($(({90-(\i-1/2)*\angdiv}:6)$)
};
\foreach [count=\a from 0] \text in {A,B,...,Z}{
\pgfmathtruncatemacro\b{\a+1}%
\path [curved text=\text] (n-\a) arc [start angle=90-(\a-1/2)*\angdiv, delta angle=-\angdiv, radius=7] node (n-\b) {};
\path [curved text=\text] (m-\a) arc [start angle=90-(\a+\caeser-1/2)*\angdiv, delta angle=-\angdiv, radius=5] node (m-\b) {}; % Inner circle
}
% draw arrows
\draw [arrows={-Latex}]
(65:9.5) to[bend left=20,edge label=$+3$] (40:9.5);
\end{tikzpicture}
\end{document}
The thing you most likely need to change in this code is the Caeser shift, which you can do so in the line of \pgfmathtruncatemacro\caeser{7}
. I have also indicated in the code exactly where it is. Note that a positive Caeser shift is a clockwise translation.
Extra: (not asked by OP)
This method is extendable to a Caeser wheel with 5 letters, for example. I've indicated the locations in the code to make the change to produce the given output.
\documentclass[tikz,border=2mm]{standalone}
\usepackage{libertine} % Change the font to your liking
\usepackage[T1]{fontenc}
\usetikzlibrary{decorations.text,arrows.meta,calc}
\tikzset{curved text/.style={decorate,
decoration={text effects along path,
text={#1}, text align=center,
text effects/.cd, text along path}}}
\begin{document}
\begin{tikzpicture}[x=1em,y=1em]
% set up
\pgfmathsetmacro\angdiv{360/5} <-----------------
\pgfmathtruncatemacro\caeser{2} % Input Caeser shift here! (positive for clockwise)
\coordinate (n-0) at (90+\angdiv/2:7) {};
\coordinate (m-0) at (90-\caeser*\angdiv+\angdiv/2:5) {};
% draw Caeser diagram
\draw circle [radius=8] circle [radius=6.5] circle [radius=6] circle [radius=4.5]
\foreach \i in {0,...,4}{% <-----------------------
($({90-(\i-1/2)*\angdiv}:8)$) -- ($(({90-(\i-1/2)*\angdiv}:6.5)$)
($({90-(\i-1/2)*\angdiv}:4.5)$) -- ($(({90-(\i-1/2)*\angdiv}:6)$)
};
\foreach [count=\a from 0] \text in {A,B,...,E}{% <------------------
\pgfmathtruncatemacro\b{\a+1}%
\path [curved text=\text] (n-\a) arc [start angle=90-(\a-1/2)*\angdiv, delta angle=-\angdiv, radius=7] node (n-\b) {};
\path [curved text=\text] (m-\a) arc [start angle=90-(\a+\caeser-1/2)*\angdiv, delta angle=-\angdiv, radius=5] node (m-\b) {}; % Inner circle
}
% draw arrows
\draw [arrows={-Latex}]
(65:9.5) to[bend left=20,edge label=$+3$] (40:9.5);
\end{tikzpicture}
\end{document}
You can also simplify your \foreach
commands:
\documentclass{article}
\usepackage{chancery}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\tikzset{curved text/.style={
decoration={text effects along path,
text/.expanded=#1, text align = center,
text effects/.cd, text along path, decorate}}
}
\begin{document}
\begin{tikzpicture}[x = 1em, y = 1em]
\draw circle [radius = 15] circle [radius = 12] circle [radius = 9]
\foreach \i in {0,...,25}{ (\i*13.85:15) -- (\i*13.85:12) -- (\i*13.85:9) };
\node [align=center] {Caesar \\ Cipher};
\foreach [count=\a from 0] \text in {X,Y,Z,A,B,...,W}
\foreach \t [count=\r] in \text
\path [curved text=\t, rotate=-\a*13.85]
(90:15-\r) arc (90:13.85:15-\r);
\foreach [count=\b from 0] \text in {A,B,...,Z}
\foreach \t [count=\r] in \text
\path [curved text=\t, rotate=-\b*13.85]
(90:12-\r) arc (90:13.85:12-\r);
\draw[->](55:16) arc(55:13.85:16) node[midway, above, xshift=6pt]{$+3$};
\end{tikzpicture}
\end{document}
A version with the shift as an optional argument (default 3).
\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand\Ceasar[1][3]{%
\begin{tikzpicture}
\def\R{2}
\def\dR{0.5}
\def\Ri{1.4}
\def\dRi{0.5}
\def\Rotate{#1}%% Number of shifts
\coordinate (origin) at (0,0);
\draw[fill=gray!60] (origin) circle (1pt);
\draw (origin) circle (\R);
\draw (origin) circle (\R+\dR);
\draw (origin) circle (\Ri);
\draw (origin) circle (\Ri+\dRi);
\foreach \Letter [count=\ind from 0,evaluate=\ind as \ang using 90-\ind*360/26] in {A,B,...,Z}{%
\node[rotate={\ang-90}] at ($(origin)+(\ang:{\R+\dR/2})$) {\Letter};
\draw({\ang+0.5*360/26}:\R)--({\ang+0.5*360/26}:\R+\dR);
}
\foreach \Letter [count=\ind from 0,evaluate=\ind as \ang using 90-\ind*360/26-\Rotate*360/26] in {A,B,...,Z}{%
\node[rotate={\ang-90}] at ($(origin)+(\ang:{\Ri+\dRi/2})$) {\Letter};
\draw({\ang+0.5*360/26}:\Ri)--({\ang+0.5*360/26}:\Ri+\dRi);
}
\draw[-latex] (90:\Ri-0.3) arc (90:{90-\Rotate*360/26}:\Ri-0.3)node[pos=0.5,anchor=90-\Rotate*180/26]{$\Rotate$};
\end{tikzpicture}
}
\begin{document}
\Ceasar \Ceasar[10] \Ceasar[-5]
\end{document}