Home > Linux > Programming > Perl Modules

Math::FastGF2 0.04

 User Rating:Rated by: NOT RATED0 user(s)
 Developer: Homepage / GIT: License / Price: Last Updated: Category: Declan Malone | More programs search.cpan.org Perl Artistic License / FREE April 26th, 2010, 15:05 GMT ROOT / Programming / Perl Modules

 Read user reviews (0)  Refer to a friend  Subscribe

Perl extension for fast Galois Field arithmetic

Math::FastGF2 is a Perl module that provides an interface for performing single modulo arithmetic operations on Galois Field polynomials in GF(2^8), GF(2^16) and GF(2^32). All values to be operated on are simple Perl numeric scalars which are taken to represent polynomials with binary co-efficients. For example, the value 0x53, whose binary representation is 10010011, represents the polynomial:

7 6 5 4 3 2 1 0
(1)x + (0)x + (0)x + (1)x + (0)x + (0)x + (1)x + (1)x

or, simply:

7 4
x + x + x + 1

Operations such as multiplication, division and calculating powers operate on the polynomials rather than the binary values. Also, all such calculations are done modulo another polynomial, which is called the irreducible polynomial for the field. For GF(2^8), the irreducible polynomial used here has the hex value 0x11b (decimal 283). In binary this is 100011011, so this represents the polynomial

8 4 3
x + x + x + x + 1

The irreducible polynomials used for fields GF(2^16) and GF(2^32) have 16 and 32 as their highest power of x, respectively. It follows that since all calculations in these fields are done modulo the appropriate irreducible polynomial that all field elements in GF(2^8) will fit in a single 8-bit byte, that GF(2^16) elements fit in a single 16-bit word, and so on.

Addition of polynomials in GF(2^n) is accomplished by xoring the binary representation of the two polynomials being operated on. Since field elements are stored as simple Perl scalars, the regular ^ (xor) operator suffices, and hence this module does not provide any gf2_add or gf2_sub methods (there is no difference between addition and subtraction in GF(2^n); the xor operator works for both).

For more detailed descriptions of arithmetic in Galois Fields, and some applications, consult the references listed below.

SYNOPSIS

use Math::FastGF2 ":ops";
use strict;
my (\$a,\$b,\$c,\$d);

\$a = gf2_mul(8,0x53,0xca); # GF(2^8) multiplication mod {11B}
\$b = gf2_inv(8,0x53); # 1 / {53} mod {11B}
\$c = gf2_div(8,0x53,0xca; # {53} / {CA} mod {11B}
\$d = gf2_pow(8,0x53,3); # {53} * {53} * {53} mod {11B}
\$a = \$b ^ \$c ^ \$d

Requirements:

TAGS:

Galois Field arithmetic | Perl module | Galois | Field | arithmetic

Go to top