Your skill will accomplishwhat the force of many cannot PerlMonks

### Japh algebra, GF(128) edition

by ambrus (Abbot)
 on Oct 02, 2010 at 21:13 UTC Need Help??

Did you know you could evaluate a polynomial over GF(128) in perl with pack and unpack and tr? Here's how.

sub h { \$_ = \$_[0] = pack b208, 0 . unpack b362, \$_[0]; tr/\0-\c?/\0/; tr/\0/\377/c; \$_ } for (split //, "k6sNP2B}({ambrusLB%Ox)Z]n0*zf\0I3") { \$y = \$r; \$v = join \$r = '', a .. z; \$r ^= h(\$r) & "\217" x 26 ^ h(\$v) & \$y for 0 .. 6; \$r ^= \$_ x 26; } print \$r;

This code is based on the same idea as Dollar Plus, but written in a different style, so some of the credit goes to martin.

Update: if you prefer one of these unreadable blocks of code, you can of course write this that way too (Update: reformatted blob from four lines to three.)

sub h(\$){(\$_=\$_[0]=pack b208,0 .unpack b362,\$_[0])=~tr/\0-\c?/\0/;tr /\0/\377/c;\$_}do{\$y=\$r;\$v=join\$r='',a..z;\$r^=h\$r&"\217"x26^h\$v&\$y for 0..6;\$r^=\$_ x26}for"k6sNP2B}({ambrusLB%Ox)Z]n0*zf\0I3"=~/./g;print\$r

Update: removed lots of spaces from end of lines of formatted code.

Replies are listed 'Best First'.
Re: Japh algebra, GF(128) edition
by BrowserUk (Pope) on Oct 02, 2010 at 21:46 UTC

Could you explain, (or point to an explanation of), (preferably in layman's terms), the annotation "GF(128)"?

I tried a search, but the term matches too many things to know where to start.

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
(The name GF stands for Galois field originally.)

Ah right! Those special French tobacco farms :)

Create A New User
Node Status?
node history
Node Type: obfuscated [id://863110]
Approved by planetscape
Front-paged by planetscape
help
Chatterbox?
 [karlgoethebier]: now it's getting weird... [GotToBTru]: 'getting'? [Discipulus]: why karlgoethebier ? [GotToBTru]: ugh .. what's the term for comparing versions of an algorithm to determine which is most efficient? [hippo]: Benchmarking? [GotToBTru]: hippo++ erix .oO( apparently but does not GotToBFast )

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2017-06-22 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (519 votes). Check out past polls.