Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 41
#---------------------------------------------------------------- # File name: GFq Addition and Multiplication Table.sage # by Chong Zan Kai # Email [email protected] # # To build the addition and multiplication tables for GF(2^q). # # Last modified on 01-May-2015. # Share at https://cloud.sagemath.com/projects/6b6b76fb-7e82-4b88-9f2f-7377a502aa28/files/GFq%20Addition%20and%20Multiplication%20Table.sagews #---------------------------------------------------------------- # # User # q = 2**2 # select the q. GF(q). # # # GFq = GF(q, 'x') GFq_list = sorted(GFq) # # Build addition table for GF(2^q) # addition_list_list = [] for a in GFq_list: addition_list = [ a + b for b in GFq_list] addition_list_list.append(addition_list) __header_row = GFq_list __header_col = ['+'] + GFq_list print ('Addition Table for GF(%d)' % q) print table(header_row = __header_row, header_column= __header_col, rows=addition_list_list, frame = True, align = 'center') print # # Build multiplication table for GF(2^q) # multiplication_list_list = [] for a in GFq_list: multiplication_list = [ a* b for b in GFq_list] multiplication_list_list.append(multiplication_list) __header_row = GFq_list __header_col = ['*'] + GFq_list print ('Multiplication Table for GF(%d)' % q) print table(header_row = __header_row, header_column= __header_col, rows=multiplication_list_list, frame = True, align = 'center') # print table(header_row = __header_row, header_column= __header_col, rows=multiplication_list_list, align = 'center')
Addition Table for GF(4) +-------++-------+-------+-------+-------+ | + || 0 | 1 | x | x + 1 | +=======++=======+=======+=======+=======+ | 0 || 0 | 1 | x | x + 1 | +-------++-------+-------+-------+-------+ | 1 || 1 | 0 | x + 1 | x | +-------++-------+-------+-------+-------+ | x || x | x + 1 | 0 | 1 | +-------++-------+-------+-------+-------+ | x + 1 || x + 1 | x | 1 | 0 | +-------++-------+-------+-------+-------+ Multiplication Table for GF(4) +-------++---+-------+-------+-------+ | * || 0 | 1 | x | x + 1 | +=======++===+=======+=======+=======+ | 0 || 0 | 0 | 0 | 0 | +-------++---+-------+-------+-------+ | 1 || 0 | 1 | x | x + 1 | +-------++---+-------+-------+-------+ | x || 0 | x | x + 1 | 1 | +-------++---+-------+-------+-------+ | x + 1 || 0 | x + 1 | 1 | x | +-------++---+-------+-------+-------+