• 大小: 3KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: Matlab
  • 标签: matlab  

资源简介

根据信息安全课程中学习的密码学算法用程序编辑了BM算法-Matlab程序

资源截图

代码片段和文件信息

clc;
clear
a=[001110];
syms x;
fx=[];%多项式
fx(1)=1;
lc=[];%L
constantpoly=[1];
lc(1)=0;
sequenlength=length(a);  % 序列长度
minpolycoefficient=[1];
minpolylen=length(minpolycoefficient);
minpolydegree=minpolylen-1;
d=[];
count1=0;
count2=0;
for n=0:sequenlength-1
    dtemp=0;
    for j=0:minpolydegree
        dtemp=mod(dtemp+minpolycoefficient(j+1)*a(n+1-minpolydegree+j)2);
    end
    d=[d dtemp];
    if d(n+1)==0
        fxtemp=fx(n+1);
        lctemp=lc(n+1);
    else
        for i=0:n
            if lc(i+1)==0
                count1=count1+1;
            else
                count1=count1;
            end
        end
        keyscript=[0];
        if count1==n+1
            fxtemp=1+x^(n+1);
            lctemp=n+1;
            keyscript=[keyscript n];
        else
            for k=0:(n-1)
                if lc(k+1)==lc(k+2)
                    keyscript=keyscript;
                else
                    keyscript=[keyscript k];
                end
            end
            keyscript=[keyscript n];
            keyscriptlength=length(keyscript);
            ntemp=keyscript(keyscriptlength);
            mtemp=keyscript(keyscriptlength-1);
            if mtemp==0
                fxtemp=fx(ntemp+1)+x^ntemp;
            else
                fxmcoefficient=sym2poly(fx(mtemp+1));
                fxmlen=length(fxmcoefficient);
                xnmcoefficient=sym2poly(x^(ntemp-mtemp));
   

评论

共有 条评论