2013-10-25 80 views
-4

我是完全新编程,我发现这个代码在网络中我知道它的语法是正确的,但我不知道如何调用SAES_FromStateMatrix函数,所以请帮助我 这里是代码在Python中调用函数

F = GF(2); 
L.<a> = GF(2^4); 
V = L.vector_space(); 
VF8 = VectorSpace(F, 8); 
MixColumns_matrix = Matrix(L, [[1,a^2],[a^2,1]]); 
InverseMixColumns_matrix = MixColumns_matrix.inverse(); 
SBox_matrix = Matrix(L, 
         [ 
         [  1 + a^3,   a^2,   a + a^3, 1 + a + a^3], 
         [ 1 + a^2 + a^3,    1,    a^3,  1 + a^2], 
         [  a + a^2,    a,     0,  1 + a], 
         [  a^2 + a^3, a + a^2 + a^3, 1 + a + a^2 + a^3, 1 + a + a^2] 
         ]); 
InverseSBox_matrix = Matrix(L, 
         [ 
         [ a + a^3,  1 + a^2,  1 + a^3,  1 + a + a^3], 
         [   1, 1 + a + a^2,   a^3, 1 + a + a^2 + a^3], 
         [ a + a^2,   0,    a,    1 + a], 
         [ a^2 + a^3,   a^2, 1 + a^2 + a^3,  a + a^2 + a^3] 
         ]); 
RCON = [ 
VF8([F(0), F(0), F(0), F(0), F(0), F(0), F(0), F(1)]), 
VF8([F(0), F(0), F(0), F(0), F(1), F(1), F(0), F(0)]) 
    ];  
def SAES_ToStateMatrix(block): 
    B = block 
    S00 = L(V([B[0], B[1], B[2], B[3]])); 
    S01 = L(V([B[4], B[5], B[6], B[7]])); 
    S10 = L(V([B[8], B[9], B[10], B[11]])); 
    S11 = L(V([B[12], B[13], B[14], B[15]])); 
    state_matrix = Matrix(L, [[S00,S01],[S10,S11]]); 
    return state_matrix; 
def SAES_FromStateMatrix(state_matrix): 
    output = []; 
    for r in xrange(2): 
    for c in xrange(2): 
     v = V(state_matrix[r,c]); 
     for j in xrange(4): 
      output.append(Integer(v[j])); 
return output; 

回答

0

我知道它的语法是正确的

不,不是这样的。

我不知道如何调用SAES_FromStateMatrix

只是做SAES_FromStateMatrix(state_matrix)其中state_matrix是一些矩阵。

我的意思是如何传递函数矩阵...其他意思SAES_FromStateMatrix(what_is_the_syntax_of_this_parameter)

用作已经存在的代码相同的语法您发布。你发布的大部分代码都是矩阵的例子。或者,使用已分配矩阵的变量,如SBox_matrix

+0

我的意思是如何调用矩阵 –

+0

您没有一个名为'matrix'的函数。你究竟想要做什么? – kindall

+0

我的意思是如何传递函数中的矩阵...在其他含义SAES_FromStateMatrix(what_is_the_syntax_of_this_parameter) –