note
ambrus
<spoiler>
<p>
Let's start from a bit farther. This series of obfus works by storing a polynomial and evaluating it at different places to get the message.
<p>
For example, suppose you wanted to print the message <c>3, 8, 0</c>. You could then create the polynomial <c>f(x) = 3 + 11.5*x - 6.5*x**2</c>, for which <c>f(0), f(1), f(2)</c> gives the values you want, and write code like this to evaluate that polynomial.
<c>
for $x (0 .. 2) { $y = 0; $y = $_ + $x * $y for qw"6.5 -11.5 3"; say $y; }
</c>
<p>
Now the problem with this method is numeric precision: if you wanted to do the same thing if you want to get 26 values (the character codes of a 26 character long message), you either couldn't do it with floating point at all, or you'd have to give the coefficients to lots of decimal digits of precision.
<p>
There's however an easy solution, which is to compute the polynomial modulo a convenient prime, namely 127. This is what [id://309529], [id://581159], and [id://862574] does (read the first one, for that has almost no obfuscation layer apart from this). We call this computing over the finite field of size 127, that is, over GF(127). (The name GF stands for Galois field originally.)
<p>
Now, computing over a prime field like GF(127) is easy because you just add or multiply two elements by adding or multiplying them as integers and then taking the result modulo 127. The obfu is thus as simple as
<c>
for $x (0 .. 25) { $y = 0; ($y = $_ + $x * $y) % 127 for @coeffs; say $y; }
</c>
<p>
Now, if a field is not a prime field, such as GF(128), then it's not so simple to do the computation, though it's also not too complicated as the brevity of the obfus show in hindsight. That's why I wondered what such an obfu would look like before [martin] wrote [id://862789|one], and before I dreamt this one.
<p>
As for why I asked for GF(128) instead of some other field, the reason is brevity. To make the code simple enough, the field should be large enough that each element could encode a character of the output, but small enough that each element in the coefficient vector can be stored as a single character in the obfu. (There could be a challenge here though, seeing whether it's possible to do calculations over GF(125) or similar in just a few lines, or using two characters per field element for a larger field.)
</spoiler>
<p>
<b>Update:</b> hide all behind spoiler tags.
863110
863116