viff

changeset 777:25b3944dc403

Removed _exp_table and _inv_table from module scope.
author Martin Geisler <mg@daimi.au.dk>
date Fri, 23 May 2008 10:13:08 +0200
parents 577c1e069d06
children d1f1b8da12bb
files viff/field.py
diffstat 1 files changed, 10 insertions(+), 16 deletions(-) [+]
line diff
     1.1 --- a/viff/field.py	Fri May 23 10:10:52 2008 +0200
     1.2 +++ b/viff/field.py	Fri May 23 10:13:08 2008 +0200
     1.3 @@ -75,14 +75,6 @@
     1.4      """Common base class for elements."""
     1.5  
     1.6  
     1.7 -#: Logarithm table.
     1.8 -#:
     1.9 -#: Maps a value *x* to *log3(x)*. See `_generate_tables`.
    1.10 -_log_table = {}
    1.11 -#: Exponentiation table.
    1.12 -#:
    1.13 -#: Maps a value *y* to *3^y*. See `_generate_tables`.
    1.14 -_exp_table = {}
    1.15  #: Inversion table.
    1.16  #:
    1.17  #: Maps a value *x* to *x^-1*. See `_generate_tables`.
    1.18 @@ -270,31 +262,33 @@
    1.19  
    1.20      Code adapted from http://www.samiam.org/galois.html.
    1.21      """
    1.22 +    log_table = {}
    1.23 +    exp_table = {}
    1.24      a = 1
    1.25      for c in range(255):
    1.26          a &= 0xff
    1.27 -        _exp_table[c] = a
    1.28 +        exp_table[c] = a
    1.29          d = a & 0x80
    1.30          a <<= 1
    1.31          if d == 0x80:
    1.32              a ^= 0x1b
    1.33 -        a ^= _exp_table[c]
    1.34 -        _log_table[_exp_table[c]] = c
    1.35 -    _exp_table[255] = _exp_table[0]
    1.36 -    _log_table[0] = 0
    1.37 +        a ^= exp_table[c]
    1.38 +        log_table[exp_table[c]] = c
    1.39 +    exp_table[255] = exp_table[0]
    1.40 +    log_table[0] = 0
    1.41  
    1.42      for x in range(256):
    1.43          for y in range(256):
    1.44              if x == 0 or y == 0:
    1.45                  z = 0
    1.46              else:
    1.47 -                log_product = (_log_table[x] + _log_table[y]) % 255
    1.48 -                z = _exp_table[log_product]
    1.49 +                log_product = (log_table[x] + log_table[y]) % 255
    1.50 +                z = exp_table[log_product]
    1.51              _mul_table[(x,y)] = GF256(z)
    1.52  
    1.53      #_inv_table[0] = 0
    1.54      for c in range(1, 256):
    1.55 -        _inv_table[c] = GF256(_exp_table[255 - _log_table[c]])
    1.56 +        _inv_table[c] = GF256(exp_table[255 - log_table[c]])
    1.57  
    1.58  _generate_tables()
    1.59