-
Notifications
You must be signed in to change notification settings - Fork 1
/
tikzlibrarycipher.code.tex
514 lines (473 loc) · 20.6 KB
/
tikzlibrarycipher.code.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% TIKZLIBRARY CIPHER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Utilities for drawing cryptographic circuits %
% Version: 2021-04-21 %
% Author: Maria Eichlseder %
% \usetikzlibrary{cipher} %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% SHAPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% UTILS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% from https://tex.stackexchange.com/questions/14769/add-more-anchors-to-standard-tikz-nodes
\newcommand{\anchorlet}[2]{%
\global\expandafter
\let\csname pgf@anchor@\pgf@sm@shape@name @#1\expandafter\endcsname
\csname pgf@anchor@\pgf@sm@shape@name @#2\endcsname
}
%%% OPERATION SHAPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfdeclareshape{oplus}{%{{{
\inheritsavedanchors[from=circle]
\inheritanchorborder[from=circle]
\foreach \s in {center,mid,base,text, north,south,west,east,
mid west,mid east,base west,base east,
north west,south west,north east,south east} {
\inheritanchor[from=circle]{\s}
}
%\inheritbackgroundpath[from=circle]
% From /usr/share/texlive/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.code.tex:1148
\backgroundpath{%
\pgfutil@tempdima=\radius%
\pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
\pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
\ifdim\pgf@xb<\pgf@yb%
\advance\pgfutil@tempdima by-\pgf@yb%
\else%
\advance\pgfutil@tempdima by-\pgf@xb%
\fi%
\pgfpathcircle{\centerpoint}{\pgfutil@tempdima}%
% north-south
\centerpoint\advance\pgf@y by\radius \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\centerpoint\advance\pgf@y by-\radius \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
% east-west
\centerpoint\advance\pgf@x by\radius \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\centerpoint\advance\pgf@x by-\radius \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
}
}%}}}
\pgfdeclareshape{ominus}{%{{{
\inheritsavedanchors[from=circle]
\inheritanchorborder[from=circle]
\foreach \s in {center,mid,base,text, north,south,west,east,
mid west,mid east,base west,base east,
north west,south west,north east,south east} {
\inheritanchor[from=circle]{\s}
}
%\inheritbackgroundpath[from=circle]
% From /usr/share/texlive/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.code.tex:1148
\backgroundpath{%
\pgfutil@tempdima=\radius%
\pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
\pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
\ifdim\pgf@xb<\pgf@yb%
\advance\pgfutil@tempdima by-\pgf@yb%
\else%
\advance\pgfutil@tempdima by-\pgf@xb%
\fi%
\pgfpathcircle{\centerpoint}{\pgfutil@tempdima}%
% east-west
\centerpoint\advance\pgf@x by\radius \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\centerpoint\advance\pgf@x by-\radius \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
}
}%}}}
\pgfdeclareshape{otimes}{%{{{
\inheritsavedanchors[from=circle]
\inheritanchorborder[from=circle]
\foreach \s in {center,mid,base,text, north,south,west,east,
mid west,mid east,base west,base east,
north west,south west,north east,south east} {
\inheritanchor[from=circle]{\s}
}
%\inheritbackgroundpath[from=circle]
% From /usr/share/texlive/texmf-dist/tex/generic/pgf/modules/pgfmoduleshapes.code.tex:1148
\backgroundpath{%
\pgfutil@tempdima=\radius%
\pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%
\pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%
\ifdim\pgf@xb<\pgf@yb%
\advance\pgfutil@tempdima by-\pgf@yb%
\else%
\advance\pgfutil@tempdima by-\pgf@xb%
\fi%
\pgfpathcircle{\centerpoint}{\pgfutil@tempdima}%
% nw-se
\centerpoint
\pgf@xc=\radius
\advance\pgf@x by-0.707107\pgf@xc \pgf@xa=\pgf@x
\advance\pgf@y by 0.707107\pgf@xc \pgf@ya=\pgf@y
\centerpoint
\advance\pgf@x by 0.707107\pgf@xc \pgf@xb=\pgf@x
\advance\pgf@y by-0.707107\pgf@xc \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
% sw-ne
\centerpoint
\advance\pgf@x by-0.707107\pgf@xc \pgf@xa=\pgf@x
\advance\pgf@y by-0.707107\pgf@xc \pgf@ya=\pgf@y
\centerpoint
\advance\pgf@x by 0.707107\pgf@xc \pgf@xb=\pgf@x
\advance\pgf@y by 0.707107\pgf@xc \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
}
}%}}}
\pgfdeclareshape{boxplus}{%{{{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \s in {center,mid,base,text, north,south,west,east,
mid west,mid east,base west,base east,
north west,south west,north east,south east} {
\inheritanchor[from=rectangle]{\s}
}
\backgroundpath{
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% store center in xc/yc
\pgf@xc=.5\pgf@xa \advance\pgf@xc by .5\pgf@xb
\pgf@yc=.5\pgf@ya \advance\pgf@yc by .5\pgf@yb
% construct main path
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
\pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
}
}%}}}
%%% PRIMITIVE SHAPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfdeclareshape{compressionf}{%{{{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \s in {center,base,text,
north,south,west,east,
north west, south west, north east, south east} {
\inheritanchor[from=rectangle]{\s}
}
\anchor{msg}{\southwest \pgf@xa=\pgf@x
\northeast \pgf@x=\pgf@xa}
\anchor{tip}{\southwest \pgf@xa=\pgf@x
\northeast
\pgf@x=\pgf@xa
\advance\pgf@y by \pgf@y}
\anchor{top}{\southwest \pgf@xa=\pgf@x
\northeast
\advance\pgf@x by-.5\pgf@x
\advance\pgf@x by .5\pgf@xa
\advance\pgf@y by .5\pgf@y}
\backgroundpath{
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@xc=\pgf@xa
\pgf@yc=\pgf@yb \advance\pgf@yc by \pgf@yb
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
}
}%}}}
\pgfdeclareshape{compression}{%{{{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \s in {center,base,text,
north,south,west,east,
north west, south west, north east, south east} {
\inheritanchor[from=rectangle]{\s}
}
\backgroundpath{
% store lower left in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@xc=\pgf@xa \advance\pgf@xc by .75\pgf@xa
\pgf@yc=\pgf@xb \advance\pgf@yc by-.75\pgf@xa
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@yc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
}
}%}}}
\pgfdeclareshape{filter}{%{{{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \s in {center,base,text,
north,south,west,east,
north west, south west, north east, south east} {
\inheritanchor[from=rectangle]{\s}
}
\backgroundpath{
% store lower left in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@xc=\pgf@xa \advance\pgf@xc by .75\pgf@xa
\pgf@yc=\pgf@xb \advance\pgf@yc by-.75\pgf@xa
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@yc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
}
}%}}}
\pgfdeclareshape{authentication}{%{{{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \s in {center,base,text,
north,south,west,east,
north west, south west, north east, south east} {
\inheritanchor[from=rectangle]{\s}
}
\anchor{tag}{\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
%\southwest \pgf@x=\pgf@xa}
\southwest \pgf@x=\pgf@xa \advance\pgf@y by .5\pgf@y \advance\pgf@y by -.5\pgf@ya}
\anchor{tip}{\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest
\pgf@x=\pgf@xa
%\advance\pgf@y by \pgf@y}
\advance\pgf@y by \pgf@y \advance\pgf@y by -\pgf@ya}
\anchor{bot}{\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest
\advance\pgf@x by-.5\pgf@x
\advance\pgf@x by .5\pgf@xa
%\advance\pgf@y by .5\pgf@y}
\advance\pgf@y by .5\pgf@y \advance\pgf@y by -.5\pgf@ya}
\backgroundpath{
% store upper right in xa/ya and lower left in xb/yb
\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@xc=\pgf@xa
%\pgf@yc=\pgf@yb \advance\pgf@yc by \pgf@yb
\pgf@yc=\pgf@yb \advance\pgf@yc by \pgf@yb \advance\pgf@yc by -\pgf@ya
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
}
}%}}}
\pgfdeclareshape{wide}{%{{{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\foreach \s in {center,base,text,
north,south,west,east,
north west, south west, north east, south east} {
\inheritanchor[from=rectangle]{\s}
}
\anchor{wnw}{\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \advance\pgf@y by-.75\pgf@y
\advance\pgf@y by .75\pgf@ya}
\anchor{wsw}{\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \advance\pgf@y by-.25\pgf@y
\advance\pgf@y by .25\pgf@ya}
\anchor{ene}{\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \advance\pgf@y by-.25\pgf@y
\advance\pgf@y by .25\pgf@ya}
\anchor{ese}{\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \advance\pgf@y by-.75\pgf@y
\advance\pgf@y by .75\pgf@ya}
\anchor{nnw}{\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \advance\pgf@x by-.75\pgf@x
\advance\pgf@x by .75\pgf@xa}
\anchor{nne}{\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \advance\pgf@x by-.25\pgf@x
\advance\pgf@x by .25\pgf@xa}
\anchor{ssw}{\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \advance\pgf@x by-.25\pgf@x
\advance\pgf@x by .25\pgf@xa}
\anchor{sse}{\northeast \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\southwest \advance\pgf@x by-.75\pgf@x
\advance\pgf@x by .75\pgf@xa}
\inheritbackgroundpath[from=rectangle]
\anchorlet{xouter}{wnw}
\anchorlet{youter}{ene}
\anchorlet{xinner}{wsw}
\anchorlet{yinner}{ese}
}%}}}
% TODO keyed north/west/south/east
%%% OTHER SHAPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfdeclareshape{document}{%{{{
% paper with folded corner
% from PGF manual, "Command for Declare New Shapes"
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
%\inheritanchor[from=rectangle]{center}
%\inheritanchor[from=rectangle]{north}
%\inheritanchor[from=rectangle]{south}
%\inheritanchor[from=rectangle]{west}
%\inheritanchor[from=rectangle]{east}
\foreach \s in {center,mid,base,text,north,south,west,east,
mid west,mid east,base west,base east,
north west,south west,north east,south east} {
\inheritanchor[from=rectangle]{\s}
}
\backgroundpath{
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% compute corner of ‘‘flipped page’’
\pgf@xc=\pgf@xb \advance\pgf@xc by-5pt % this should be a parameter
\pgf@yc=\pgf@yb \advance\pgf@yc by-5pt
% construct main path
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
% add little corner
\pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
}
}
\pgfdeclareshape{minidocument}{
% paper with folded corner
% from PGF manual, "Command for Declare New Shapes"
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\backgroundpath{
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
% compute corner of ‘‘flipped page’’
\pgf@xc=\pgf@xb \advance\pgf@xc by-2pt % this should be a parameter
\pgf@yc=\pgf@yb \advance\pgf@yc by-2pt
% construct main path
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
\pgfpathclose
% add little corner
\pgfpathmoveto{\pgfpoint{\pgf@xc}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yc}}
\pgfpathlineto{\pgfpoint{\pgf@xc}{\pgf@yc}}
}
}
\tikzset{doc/.style={draw, fill=none, shape=document}}
\tikzset{minidoc/.style={draw, fill=none, shape=minidocument}}
%}}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% MATRIX STATE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\providecommand{\State}[1]{\MatrixState{#1}} % load library late to avoid name conflicts
\newcommand{\MatrixState}[1]{%
\tikz[stateopts]{
\foreach \x/\y/\s in {0/0/0, 0/1/1, 0/2/2, 0/3/3,
1/0/4, 1/1/5, 1/2/6, 1/3/7,
2/0/8, 2/1/9, 2/2/10,2/3/11,
3/0/12,3/1/13,3/2/14,3/3/15} {
%
\draw (\y+.5,-\x-.5) coordinate (s\s) coordinate (ss\x\y); % (rowwise indices)
\draw (\x+.5,-\y-.5) coordinate (b\s); % AES indices (columnwise)
}
\draw (2,-2) coordinate (label);
#1
\draw (0,0) rectangle (4,-4);
\foreach \x in {1,2,3} {
\draw[raster] (0,-\x) -- ++(4,0);
\draw[raster] (\x,0) -- ++(0,-4);
}
}%
}
\newcommand{\Column}[1]{%
\tikz[stateopts]{
\foreach \x/\y/\s in {0/0/0, 1/0/4, 2/0/8, 3/0/12} {
\draw (\y+.5,-\x-.5) coordinate (s\s) coordinate (ss\x\y); % (rowwise indices)
}
#1
\draw (0,0) rectangle (1,-4);
\foreach \x in {1,2,3} { \draw[raster] (0,-\x) -- ++(1,0); }
}%
}
\newcommand{\Cell}[2]{\draw (#1) node[inner sep=0pt,cellopts] {#2\vphantom{0}};}
\newcommand{\FillCell}[2][fillopts]{\fill[#1] (#2) ++(-.5,.5) rectangle +(1,-1);}
\newcommand{\Fill}[2][fillopts]{\FillCell[#1]{#2}}
\newcommand{\FillColumn}[2][fillopts]{\fill[#1] (ss0#2) ++(-.5,.5) rectangle +(1,-4);}
\newcommand{\FillDiagonal}[2][fillopts]{\foreach \dd in {0,...,3} {\pgfmathsetmacro{\dx}{mod(int(\dd)+int(#2),4)}\Fill[#1]{ss\dd\dx}}}
\newcommand{\FillAntiDiagonal}[2][fillopts]{\foreach \dd in {0,...,3} {\pgfmathsetmacro{\dx}{mod(int(#2)+4-int(\dd),4)}\Fill[#1]{ss\dd\dx}}}
\newcommand{\FillState}[1][fillopts]{\fill[#1] (0,0) rectangle (4,-4);}
% TODO check out if TiKZ matrices (tikzmanual.pdf Chapter 20) could be useful instead
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% ARROWS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usetikzlibrary{arrows.meta}
\pgfarrowsdeclare{ipe arrow}{ipe arrow}{%{{{
\pgfutil@tempdima=5pt\relax
\advance\[email protected]\pgflinewidth
\pgfarrowsleftextend{+-\pgfutil@tempdima}%
\pgfarrowsrightextend{+1.5\pgflinewidth}%
}{%
\pgftransformshift{\pgfqpoint{1.5\pgflinewidth}{0pt}}%
\pgfpathmoveto{\pgfpointorigin}%
\pgfpathlineto{\pgfqpoint{-5pt}{-1.666pt}}%
\pgfpathlineto{\pgfqpoint{-5pt}{+1.666pt}}%
\pgfpathclose
\pgfusepathqfill
}%}}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% STYLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% OPERATION STYLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{op/.style={draw, fill=none, minimum size=1.5ex, inner sep=0pt}}
\tikzset{xor/.style={op, shape=oplus}}
\tikzset{not/.style={op, shape=ominus}}
\tikzset{mul/.style={op, shape=otimes}}
\tikzset{and/.style={op, shape=otimes}} % TODO \odot
\tikzset{sum/.style={op, shape=boxplus}}
\tikzset{tee/.style={shape=circle, fill, draw, inner sep=0pt, minimum size=2pt}}
\tikzset{rot/.style={shape=rectangle, draw, inner sep=2pt, rounded corners=2pt}} % TODO
%%% PRIMITIVE STYLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{box/.style={minimum size=.75cm, draw, inner sep=1pt, fill=white, rounded corners=3pt}}
\tikzset{
key west/.style={path picture={\draw[line cap=round,rounded corners=0pt] (path picture bounding box.west) +(.25pt,.65ex) -- +(.65ex,0) -- +(.25pt,-.65ex);}},
key east/.style={path picture={\draw[line cap=round,rounded corners=0pt] (path picture bounding box.east) +(-.25pt,.65ex) -- +(-.65ex,0) -- +(-.25pt,-.65ex);}},
key north/.style={path picture={\draw[line cap=round,rounded corners=0pt] (path picture bounding box.north) +(-.65ex,-.25pt) -- +(0,-.65ex) -- +(.65ex,-.25pt);}},
key south/.style={path picture={\draw[line cap=round,rounded corners=0pt] (path picture bounding box.south) +(-.65ex,.25pt) -- +(0,.65ex) -- +(.65ex,.25pt);}},
key at/.style args = {#1}{path picture={\draw[line cap=round,rounded corners=0pt] (path picture bounding box.#1) +(-.65ex,.25pt) -- +(0,.65ex) -- +(.65ex,.25pt);}},
}
%%% ARROW STYLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{next/.style={->, >=ipe arrow}}
\tikzset{prev/.style={<-, >=ipe arrow}}
%%% MATRIX STATE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{
state/.style={inner sep=0pt},
stateopts/.style={scale=.3},
raster/.style={},
fillopts/.style={gray},
cellopts/.style={},
}
% TODO provide settings that prefill nodes with \State{}
% TODO alternative shapes -- careful, they mess up with chained comments and relative coordinates!
\tikzset{
notalt/.style={draw,circle,append after command={
[shorten >=\pgflinewidth, shorten <=\pgflinewidth]
(\tikzlastnode.east) edge (\tikzlastnode.west)
}},
xoralt/.style={draw,circle,append after command={
[shorten >=\pgflinewidth, shorten <=\pgflinewidth]
(\tikzlastnode.north) edge (\tikzlastnode.south)
(\tikzlastnode.east) edge (\tikzlastnode.west)
}},
andalt/.style={op, shape=circle, every label/.style={}, label={center:\tikz{\filldraw circle (.75pt);}} },
}
% vim: foldmethod=marker