aboutsummaryrefslogtreecommitdiffstats
path: root/buch/chapters/90-crypto/images/sbox.m
blob: 973ffc95fcc934bb2aca4436a9fb8de16fbb80b2 (plain)
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
#
# sbox.m
#
# (c) 2021 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
#
A=[
1,0,0,0,1,1,1,1;
1,1,0,0,0,1,1,1;
1,1,1,0,0,0,1,1;
1,1,1,1,0,0,0,1;
1,1,1,1,1,0,0,0;
0,1,1,1,1,1,0,0;
0,0,1,1,1,1,1,0;
0,0,0,1,1,1,1,1;
]

R = zeros(8,16);
R(:,1:8) = A;
R(:,9:16) = eye(8);

for k = (1:5)
	for i=(k+1:8)
		pivot = R(i,k);
		R(i,:) = R(i,:) + pivot * R(k,:);
	end
	R = mod(R, 2)
end

P = [
1,0,0,0,0,0,0,0;
0,1,0,0,0,0,0,0;
0,0,1,0,0,0,0,0;
0,0,0,1,0,0,0,0;
0,0,0,0,1,0,0,0;
0,0,0,0,0,0,0,1;
0,0,0,0,0,1,0,0;
0,0,0,0,0,0,1,0;
]

R = P * R

for k = (8:-1:2)
	for i = (1:k-1)
		pivot = R(i,k);
		R(i,:) = R(i,:) + pivot * R(k,:);
	end
	R = mod(R, 2)
end

B = R(:,9:16)

A * B