Full MatrixSpace of 1 by 4 dense matrices over Finite Field of size 2' and 'Symbolic Ring' !!! can anyone know how to resolve this ?

asked 2022-11-16 09:31:26 +0200

nassair gravatar image

updated 2022-11-16 18:35:35 +0200

Max Alekseyev gravatar image

hello , i'm trying to implement mc_eliece ( case of goppa code ) on sage math and then i got this error : unsupported operand parent(s) for +: 'Full MatrixSpace of 1 by 4 dense matrices over Finite Field of size 2' and 'Symbolic Ring'

can anyone know how to solve this problem ? thanks

import numpy as np # generation du code de copa



def initialisation() :  

    global n;
    global G;
    global k;
    global P;
    global S
    global Gp;

    t=int(input("nombre maximal d'erreur"));


    n=int (input("longueur du message chiffree ")); 

    p=(ln(n)/ln(2));

    F=GF(2^p);

    R.<x>=F[];

    g=(x^t +x +1)^2 ; 


    L=[a for a in F.list() if g(a)!=0];


    C=codes.GoppaCode(g,L) ; 

    print ( "caracteristique code de copa generer"); 

    print(C) ;


    G=C.generator_matrix() ;  # nous venons de generer la matrice generatrice de nombre de colone n 
    print( "matrice generatrice G");
    print(G);

    k=G.nrows(); # on recupere le nombre de ligne de la matrice G

    # generons la matrice de permutation de dimension   qui est une matrice de identite dont les lignes ont ete permute 

    print();



    P=matrix.identity(n);  # generons la matrice de permuation , 
    # nous devons toujours trouver un moyen pour permuter quelques lignes de facon aleatoire 
    print("matrice de permutation P");
    print(P);


    S=random_matrix(GF(2),k);
    print("matrice brouilleur S"); 
    print(S);

    #generons la cle public Gp=SGP 

    Gp1=S*G;
    Gp=Gp1*P;
    print("cle public");
    print(Gp);

    print("l'erreur introduit doit etre de longeur",n,"et de poid <= ",t);

    e2=list(map(int, list(input("enter l'erreur ")))); # convertion de chaine de caractere  liste d'entiers

    e=matrix(GF(2),1,n);  # convertion liste en matrix vecteur // ici on impose que la longueur de e a n 

    for i in range(0,n,1) :

        e[0,i]=e2[i];


    print(e);

def mc_eliece(): 

    print(Gp.nrows());
    print(Gp.ncols());

    print("votre message a envoye doit etre de longueur",k);

    m2=list(map(int, list(input("entrer votre message"))));

    print(m2);

    m=matrix(GF(2),1,k);  # convertion liste en matrix vecteur , sa longueur correspond au nombre de ligne de la generatrice  

   # vector([v[i]/w[i] for i in range(len(v))]) 

    for i in range(0,k,1) :

        m[0,i]=m2[i];


    print(m); # on a reussi a recuperer le message m sous forme de matrice . codons le maintenant . 

    print(m.nrows());


    m1=matrix(GF(2),1,n);
    m1=(m*Gp); #ensuite en fait m1+e , juste ici pour un soucis de conflit , on va preciser le corps de chaque variable 

    print(m1);

    mc=matrix(GF(2),1,n);

    mc= m1+e;# here i'm suppose to do the addition of m1 and e to get mc ; but the error occure





initialisation(); 
mc_eliece();
edit retag flag offensive close merge delete

Comments

What values are you using for the various inputs (so that others can try to reproduce the problem)?

John Palmieri gravatar imageJohn Palmieri ( 2022-11-16 18:38:33 +0200 )edit

What is the point in defining a variable and then re-defining it right away?

m1=matrix(GF(2),1,n);
m1=(m*Gp); 
...
mc=matrix(GF(2),1,n);
mc= m1+e;
Max Alekseyev gravatar imageMax Alekseyev ( 2022-11-16 21:03:20 +0200 )edit

My guess, by the way, is that e is being treated as the number 2.71828..., which in Sage is an element of the symbolic ring. You should add global e to initialisation.

John Palmieri gravatar imageJohn Palmieri ( 2022-11-16 21:04:36 +0200 )edit