Blog illustrations
This commit is contained in:
parent
e9a1608a8f
commit
abcb3137f1
6 changed files with 89 additions and 16 deletions
|
|
@ -4,6 +4,8 @@ GNU AGPL v3, CopyLeft 2025 Pascal Engélibert [(why copyleft?)](https://txmn.tk/
|
|||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.
|
||||
|
||||
This program's output may be licensed as you wish, no obligation to credit and provide a link to the source code, even if it's always better ;)
|
||||
"""
|
||||
|
||||
import math
|
||||
|
|
@ -53,23 +55,24 @@ SVG = """\
|
|||
"""
|
||||
|
||||
class Block:
|
||||
def __init__(self, svg, x, y, r):
|
||||
def __init__(self, svg, x, y, rx, ry=None):
|
||||
self.svg = svg
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.r = r
|
||||
self.rx = rx
|
||||
self.ry = ry if ry != None else rx
|
||||
|
||||
def to(self, block):
|
||||
if self.x == block.x:
|
||||
if self.y > block.y:
|
||||
self.svg.t += arrow(self.x, self.y-self.r, block.x, block.y+block.r)
|
||||
self.svg.t += arrow(self.x, self.y-self.ry, block.x, block.y+block.ry)
|
||||
else:
|
||||
self.svg.t += arrow(self.x, self.y+self.r, block.x, block.y-block.r)
|
||||
self.svg.t += arrow(self.x, self.y+self.ry, block.x, block.y-block.ry)
|
||||
elif self.y == block.y:
|
||||
if self.x > block.x:
|
||||
self.svg.t += arrow(self.x-self.r, self.y, block.x+block.r, block.y)
|
||||
self.svg.t += arrow(self.x-self.rx, self.y, block.x+block.rx, block.y)
|
||||
else:
|
||||
self.svg.t += arrow(self.x+self.r, self.y, block.x-block.r, block.y)
|
||||
self.svg.t += arrow(self.x+self.rx, self.y, block.x-block.rx, block.y)
|
||||
|
||||
XOR_R = 8
|
||||
ENCRYPT_SIZE = 32
|
||||
|
|
@ -126,12 +129,12 @@ class Svg:
|
|||
"""
|
||||
return Block(self, x, y, XOR_R)
|
||||
|
||||
def encrypt(self, x, y):
|
||||
def encrypt(self, x, y, text="E"):
|
||||
xl = x-ENCRYPT_SIZE//2
|
||||
yt = y-ENCRYPT_SIZE//2
|
||||
self.t += f"""\
|
||||
<rect x="{xl}" y="{yt}" width="{ENCRYPT_SIZE}" height="{ENCRYPT_SIZE}"/>
|
||||
<text class="t" x="{x}" y="{y}">E</text>
|
||||
<text class="t" x="{x}" y="{y}">{text}</text>
|
||||
"""
|
||||
return Block(self, x, y, ENCRYPT_SIZE//2)
|
||||
|
||||
|
|
@ -164,7 +167,13 @@ class Svg:
|
|||
tx_ = (tx+0.5)*cell_w+xl
|
||||
ty_ = (ty+0.5)*cell_h+yt
|
||||
self.t += f"""<text class="t" x="{tx_}" y="{ty_}">{t}</text>\n"""
|
||||
return Block(self, x, y, ENCRYPT_SIZE//2)
|
||||
for (x1, y1, x2, y2) in borders:
|
||||
x1_ = x1*cell_w+xl
|
||||
y1_ = y1*cell_h+yt
|
||||
x2_ = x2*cell_w+xl
|
||||
y2_ = y2*cell_h+yt
|
||||
self.t += f"""<line x1="{x1_}" y1="{y1_}" x2="{x2_}" y2="{y2_}"/>\n"""
|
||||
return Block(self, x, y, w//2, h//2)
|
||||
|
||||
def knot(self, x, y):
|
||||
self.t += f"""\
|
||||
|
|
@ -380,13 +389,58 @@ def chacha_encryption():
|
|||
(0.5, 3, "count"),
|
||||
(2.5, 3, "nonce"),
|
||||
],
|
||||
[])
|
||||
P = s.text(16, 144, "P")
|
||||
E = s.encrypt(64, 96)
|
||||
X = s.xor(64, 144)
|
||||
C = s.text(64, 180, "C")
|
||||
[
|
||||
(0, 1, 4, 1),
|
||||
(0, 3, 4, 3),
|
||||
(2, 3, 2, 4),
|
||||
])
|
||||
P = s.text(16, 160, "P")
|
||||
E = s.encrypt(64, 112)
|
||||
X = s.xor(64, 160)
|
||||
C = s.text(64, 200, "C")
|
||||
|
||||
B.to(E)
|
||||
E.to(X)
|
||||
P.to(X)
|
||||
X.to(C)
|
||||
|
||||
return SVG.format(body=s.t, title="ChaCha Encryption", w=372, h=192, **ARGS)
|
||||
return SVG.format(body=s.t, title="ChaCha Encryption", w=128, h=224, **ARGS)
|
||||
|
||||
def chacha_xts():
|
||||
s = Svg()
|
||||
B = s.block(64, 96, 4, 4, [
|
||||
(1.5, 0, "const"),
|
||||
(1.5, 1.5, "K"),
|
||||
(0.5, 3, "count"),
|
||||
(2.5, 3, "nonce"),
|
||||
],
|
||||
[
|
||||
(0, 1, 4, 1),
|
||||
(0, 3, 4, 3),
|
||||
(2, 3, 2, 4),
|
||||
])
|
||||
P = s.text(304, 16, "P")
|
||||
X1 = s.xor(304, 56)
|
||||
E1 = s.encrypt(304, 96, 'E<tspan dy="6">r</tspan>')
|
||||
X2 = s.xor(304, 144)
|
||||
C = s.text(304, 180, "C")
|
||||
|
||||
E2 = s.encrypt(176, 96)
|
||||
|
||||
J = s.text(240, 16, "j")
|
||||
A = s.square(240, 96, '×α <tspan dy="-8">j</tspan>')
|
||||
|
||||
B.to(E2)
|
||||
P.to(X1)
|
||||
X1.to(E1)
|
||||
E1.to(X2)
|
||||
X2.to(C)
|
||||
E2.to(A)
|
||||
J.to(A)
|
||||
s.t += arrow_path([(256,96), (272,96), (272,56), (296,56)])
|
||||
s.t += arrow_path([(256,96), (272,96), (272,144), (296,144)])
|
||||
|
||||
return SVG.format(body=s.t, title="XTS", w=372, h=192, **ARGS)
|
||||
|
||||
def save(name, data):
|
||||
f = open(f"{name}.svg", "w")
|
||||
|
|
@ -399,3 +453,4 @@ if __name__ == "__main__":
|
|||
save("cbc", cbc())
|
||||
save("xts", xts())
|
||||
save("../flash-filesystem-encryption-2/chacha-encryption", chacha_encryption())
|
||||
save("../flash-filesystem-encryption-2/chacha-xts", chacha_xts())
|
||||
|
|
|
|||
Loading…
Reference in a new issue