Let maj(a, b, c)
denote the majority function. The T-function (called tfunc
) operates on eight $n$-bit words and outputs eight $n$-bit words. The majority function outputs 1 bit from 3 bits (i.e. a single $n$-bit word from three $n$-bit words).
In the following pseudocode, ^
denotes the bitwise XOR operation, &
denotes the bitwise AND operation, |
denotes the bitwise OR operation, X |= Y
denotes the X = X | Y
operation, <<
denotes the left non-cyclic shift modulo $2^n$.
function tfunc([A0, A1, A2, A3, A4, A5, A6, A7]) {
B0 = A0 ^ A1 ^ A2 ^ (maj(A3, A4, A5) << 1);
B1 = A1 ^ A2 ^ A3 ^ (maj(B0, A6, A7) << 1);
B2 = A2 ^ A3 ^ A4 ^ (maj(B1, A0, A1) << 1);
B3 = A3 ^ A4 ^ A5 ^ (maj(B2, A2, A3) << 1);
B4 = A4 ^ A5 ^ A6 ^ (maj(B3, A4, A5) << 1);
B5 = A5 ^ A6 ^ A7 ^ (maj(B4, A6, A7) << 1);
B6 = A6 ^ A7 ^ A0 ^ (maj(B5, A0, A1) << 1);
B7 = A7 ^ A0 ^ A1 ^ (maj(B6, A2, A3) << 1);
return [B0, B1, B2, B3, B4, B5, B6, B7];
};
This algorithm uses the circular binary matrix $M$:
1, 1, 1, 0, 0, 0, 0, 0
0, 1, 1, 1, 0, 0, 0, 0
0, 0, 1, 1, 1, 0, 0, 0
0, 0, 0, 1, 1, 1, 0, 0
0, 0, 0, 0, 1, 1, 1, 0
0, 0, 0, 0, 0, 1, 1, 1
1, 0, 0, 0, 0, 0, 1, 1
1, 1, 0, 0, 0, 0, 0, 1
The inverse of $M$ is
0, 1, 1, 0, 1, 1, 0, 1
1, 0, 1, 1, 0, 1, 1, 0
0, 1, 0, 1, 1, 0, 1, 1
1, 0, 1, 0, 1, 1, 0, 1
1, 1, 0, 1, 0, 1, 1, 0
0, 1, 1, 0, 1, 0, 1, 1
1, 0, 1, 1, 0, 1, 0, 1
1, 1, 0, 1, 1, 0, 1, 0
But what is the correct algorithm (in the C-like pseudocode) for the inverse of tfunc
? The algorithm would look like the one in this answer (here len
denotes the number of bits in a word, which corresponds to the number $n$ mentioned in the first paragraph of the post):
function inv_tfunc([B0, B1, B2, B3, B4, B5, B6, B7]) {
A0 = (B1 ^ B2 ^ B4 ^ B5 ^ B7) & 1;
A1 = (B2 ^ B3 ^ B5 ^ B6 ^ B0) & 1;
A2 = (B3 ^ B4 ^ B6 ^ B7 ^ B1) & 1;
A3 = (B4 ^ B5 ^ B7 ^ B0 ^ B2) & 1;
A4 = (B5 ^ B6 ^ B0 ^ B1 ^ B3) & 1;
A5 = (B6 ^ B7 ^ B1 ^ B2 ^ B4) & 1;
A6 = (B7 ^ B0 ^ B2 ^ B3 ^ B5) & 1;
A7 = (B0 ^ B1 ^ B3 ^ B4 ^ B6) & 1;
for (i = 1; i < len; i = i + 1){
A0 |= (1 << i) & (???);
A1 |= (1 << i) & (???);
A2 |= (1 << i) & (???);
A3 |= (1 << i) & (???);
A4 |= (1 << i) & (???);
A5 |= (1 << i) & (???);
A6 |= (1 << i) & (???);
A7 |= (1 << i) & (???);
};
return [A0, A1, A2, A3, A4, A5, A6, A7];
}
I can only compute the least significant (linear) bits of each word. How to obtain the remaining bits?
tfunc1
is an arbitrary "T-function", what does this mean? $\endgroup$tfunc
) defines a particular function. $\endgroup$Aj
(you are there). Then you can compute the low-order bits of the themaj(…)
terms, that is the second low-order bits of the(maj(…) << 1)
terms, then use the inverse matrix to get the second low-order bits of theAj
. And so on for each bit. The rest is merely coding. $\endgroup$A0 = ...
andA1 = ...
in the loop to compute the remaining bits. Given only these two expressions, I will probably be able to write the rest of the algorithm. But what are these expressions? $\endgroup$B0 = A0^A1^A2^(maj(A3,A4,A5)<<1)
intoA0^A1^A2 = B0^(maj(A3,A4,A5)<<1)
and so on for the other 7 equations. Knowing theBj
and the low-orderi
bits of theAj
you compute the RHS (thus the LHS) toi+1
low order bits. Then you compute theAj
toi+1
low order bits using the matrix/equations already in the answer. Apply that fori
from0
ton-1
and you have all then
bits of theAj
. I suggest you write the code and answer your own question. I'd rather not, because this could be homework, and making it is the only (or at least the best) way to learn that skill. $\endgroup$