Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Japh algebra, GF(128) edition

by ambrus (Abbot)
on Oct 02, 2010 at 22:16 UTC ( #863118=note: print w/ replies, xml ) Need Help??


in reply to Re: Japh algebra, GF(128) edition
in thread Japh algebra, GF(128) edition

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.

For example, suppose you wanted to print the message 3, 8, 0. You could then create the polynomial f(x) = 3 + 11.5*x - 6.5*x**2, for which f(0), f(1), f(2) gives the values you want, and write code like this to evaluate that polynomial.

for $x (0 .. 2) { $y = 0; $y = $_ + $x * $y for qw"6.5 -11.5 3"; say $ +y; }

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.

There's however an easy solution, which is to compute the polynomial modulo a convenient prime, namely 127. This is what Japh algebra, Japh algebra revisited, and ASCII arithmetic 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.)

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

for $x (0 .. 25) { $y = 0; ($y = $_ + $x * $y) % 127 for @coeffs; say +$y; }

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 one, and before I dreamt this one.

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.)

Update: hide all behind spoiler tags.


Comment on Re^2: Japh algebra, GF(128) edition
Select or Download Code
Re^3: Japh algebra, GF(128) edition
by BrowserUk (Pope) on Oct 03, 2010 at 01:46 UTC
    (The name GF stands for Galois field originally.)

    Ah right! Those special French tobacco farms :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://863118]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-09-23 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls