Close

3:2 compression

A project log for Another Table-Based Stream Scrambler

Non-reversible, non-cryptographic scrambler for PRNG, 16 bits at a time.

yann-guidon-ygdesYann Guidon / YGDES 02/18/2025 at 09:280 Comments

There are 8 non-degenerate boolean operations with 2 inputs. For 3 inputs, it's much higher so it's harder to choose... And I'm still looking for the magic non-linear operation that is cheap, efficient and balanced.

The goal is to generate R(16) and FG(16) from Z(32) and C(17). For now, R=Y+C and it's underwhelming. The last log proposed this :

diff = X & ~Y;
Y |= diff;
X &= ~diff;

But this creates an imbalance of bit density/probability, with Y > X. It's not a real problem in the LUT datapath except when A=B, where X and Y must have the same value to prevent conflicts.

-----------------------------

Well now that I think of it, if X=Y then X&~Y=0 so there is no imbalance or conflict... D'oh. So it's pretty safe in fact. Now, to prevent a bias in the LUT, A<B must be strictly as equiprobable as A>B. Good luck with that with the lousy LFSR.

-----------------------------

This imbalance could be dithered by using a third parameter (C in this case) that selects which outputs gets the bits set, and the other output gets reset, bit by bit.

diff1 =  X & ~Y &  C;
diff2 = ~X &  Y & ~C;

Y |=  diff1;
X &= ~diff1;

X |=  diff2;
Y &= ~diff2;

It's cheap to implement as physical gates but it takes a bunch of instructions to execute on a CPU...

-----------------------------

Then there is another strategy with two "reciprocal MUX", or a "swap" operation: for each bit, C selects whether X and Y are swapped. That's a good way to get a well scrambled R and FG.

.

Discussions