基于纠错码的密码术

时间:2017-07-21 10:43:11

标签: c cryptography

我需要在C中实现McEliece,这个函数应该放一个 系统形式的矩阵。 (你需要一个这样的矩阵来加密消息 矩阵向量乘法。有人能帮我理解吗? 您可以找到所有类here的完整代码。该函数来自文件mat.c

int * mat_rref(binmat_t A)//This code is supposed to put matrix A in 
                          //systematic form. typedef struct matrix{int 
                          //rown, int coln, int alloc_size}*binmat_t;
{
  int i,j,failcnt,findrow,max=A->coln - 1;
  int *perm;

  perm = malloc(A->coln * sizeof(int));//initialise permutation

  for(i=0;i<A->coln;i++)
    perm[i]=i;//initialize permutation.
  failcnt = 0;

  for(i=0;i<A->rown;i++,max--)
    {
      findrow=0;
      for(j=i;j<A->rown;j++)
    {
      if(mat_coeff(A,j,max))//(A->elem[(j*A->coln)+max])
        {
          //max--;
          if (i!=j)//not needed as ith row is 0 and jth row is 1.
        A=mat_rowxor(A,i,j);//xor to the row.(swap)?
          findrow=1;
          break;
        }//largest value found (end if)
      //          break;
    }

      if(!findrow)//if no row with a 1 found then swap last column and the column with no 1 down.
    {
      perm[A->coln - A->rown - 1 - failcnt] = max;
      failcnt++;
      if (!max)
        {
          return NULL;
        }
      i--;
    }
      else
    {
      perm[i+A->coln - A->rown] = max;
      for(j=i+1;j<A->rown;j++)//fill the column downwards with 0's
        {
          if(mat_coeff(A,j,(max)))//(A->elem[j*A->coln+max+1])
        A=mat_rowxor(A,j,i);//check the arg. order.
        }

      for(j=i-1;j>=0;j--)//fill the column with 0's upwards too.
        {
          if(mat_coeff(A,j,(max)))//(A->elem[j*A->coln+max+1])
        A=mat_rowxor(A,j,i);
        }
    }
    }//end for(i)

  return(perm);
}

0 个答案:

没有答案