Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linear transformation function

I need to write a function that takes 4 bytes as input, performs a reversible linear transformation on this, and returns it as 4 bytes.

But wait, there is more: it also has to be distributive, so changing one byte on the input should affect all 4 output bytes.

The issues:

  • if I use multiplication it won't be reversible after it is modded 255 via the storage as a byte (and its needs to stay as a byte)
  • if I use addition it can't be reversible and distributive

One solution: I could create an array of bytes 256^4 long and fill it in, in a one to one mapping, this would work, but there are issues: this means I have to search a graph of size 256^8 due to having to search for free numbers for every value (should note distributivity should be sudo random based on a 64*64 array of byte). This solution also has the MINOR (lol) issue of needing 8GB of RAM, making this solution nonsense.

The domain of the input is the same as the domain of the output, every input has a unique output, in other words: a one to one mapping. As I noted on "one solution" this is very possible and I have used that method when a smaller domain (just 256) was in question. The fact is, as numbers get big that method becomes extraordinarily inefficient, the delta flaw was O(n^5) and omega was O(n^8) with similar crappiness in memory usage.

I was wondering if there was a clever way to do it. In a nutshell, it's a one to one mapping of domain (4 bytes or 256^4). Oh, and such simple things as N+1 can't be used, it has to be keyed off a 64*64 array of byte values that are sudo random but recreatable for reverse transformations.

like image 313
Arthur Avatar asked Sep 09 '26 14:09

Arthur


2 Answers

Balanced Block Mixers are exactly what you're looking for.

Who knew?

like image 155
Allain Lalonde Avatar answered Sep 12 '26 21:09

Allain Lalonde


Edit! It is not possible, if you indeed want a linear transformation. Here's the mathy solution:

You've got four bytes, a_1, a_2, a_3, a_4, which we'll think of as a vector a with 4 components, each of which is a number mod 256. A linear transformation is just a 4x4 matrix M whose elements are also numbers mod 256. You have two conditions:

  1. From Ma, we can deduce a (this means that M is an invertible matrix).
  2. If a and a' differ in a single coordinate, then Ma and Ma' must differ in every coordinate.

Condition (2) is a little trickier, but here's what it means. Since M is a linear transformation, we know that

M(a - a) = Ma - Ma'

On the left, since a and a' differ in a single coordinate, a - a has exactly one nonzero coordinate. On the right, since Ma and Ma' must differ in every coordinate, Ma - Ma' must have every coordinate nonzero.

So the matrix M must take a vector with a single nonzero coordinate to one with all nonzero coordinates. So we just need every entry of M to be a non-zero-divisor mod 256, i.e., to be odd.

Going back to condition (1), what does it mean for M to be invertible? Since we're considering it mod 256, we just need its determinant to be invertible mod 256; that is, its determinant must be odd.

So you need a 4x4 matrix with odd entries mod 256 whose determinant is odd. But this is impossible! Why? The determinant is computed by summing various products of entries. For a 4x4 matrix, there are 4! = 24 different summands, and each one, being a product of odd entries, is odd. But the sum of 24 odd numbers is even, so the determinant of such a matrix must be even!

like image 26
Jesse Beder Avatar answered Sep 12 '26 23:09

Jesse Beder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!