📄 ffcsr.m
字号:
% Script file: ffcsr.m
%
% Purpose:an algorithm to achieve the peseudorandom sequence with the size of T=12 by
% filtered FCSR block
%
%
% Record of revisions:
% ==== ========== =====================
% 05/17/07 Xin Li Original code
% Define variables:
% msinteger --state integer of mainregister
% csinteger --state integer of carries register
% rnd --the output sequence of the ffcsr cipher
% k --Main register size
% q --Connection integer
% d --Equivalent connection integer
% T --the period of the output sequence
% mkey --the key sequence for the main register
% ckey --the key sequence for the carries register
% m_register --the main register matrix
% cell --the carries register matrix
% F --the filter function
% S --the output sequence
function [msinteger,csinteger,rnd]=ffcsr%(mkey,ckey)
k=3;
T=12;
q=-13; %a nagative prime
d=[0 1 1 1]; % d=(abs(q)+1)/2.
F=d;
mkey=[0 0 0 1];% key.
m_register = mkey; %The main register is initialized with the key K.
newregister=zeros(1,4);
newcell=zeros(1,4);
cell=[0 0 0 0]; % Carries register is initialized to 0.
%cell=ckey;
msinteger=zeros(1,12);
csinteger=zeros(1,12);
S=zeros(1,3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The output sequence--of the FCSR%
% the state integer of mainregister and state integer of carries register--cregister of the FCSR%
% use these inters as key for mainregister and carris register%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:12
%rnd(i)=m_register(4);
for l=2:4
msinteger(i)=msinteger(i)+m_register(l)*2.^(4-l);
end
for l=2:4
csinteger(i)=csinteger(i)+cell(l)*2.^(4-l);
end
for j=2:4
newregister(j)=xor(xor(m_register(j-1),d(j)*cell(j)),d(j)*m_register(4));
newcell(j)=xor(xor(m_register(j-1)*cell(j),cell(j)*m_register(4)),m_register(j-1)*m_register(4));
end
m_register= newregister;
cell=newcell;
cell(2)=0;
end
%m_register=mkey
%cell=ckey
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Clock the FFCSR k times, extract a pseudorandom sequence S using the
%filter F%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:T
%rnd(i)=m_register(4);
rnd(i)=xor(xor(m_register(2)*F(2),m_register(3)*F(3)),m_register(4)*F(4));
for j=2:4
newregister(j)=xor(xor(m_register(j-1),d(j)*cell(j)),d(j)*m_register(4));
newcell(j)=xor(xor(m_register(j-1)*cell(j),cell(j)*m_register(4)),m_register(j-1)*m_register(4));
end
m_register= newregister;
cell=newcell;
cell(2)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% reinitialize the main register with the sequence S; Clear the carries%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%m_register=[0 S];
%cell=[0 0 0 0];
%for i=1:T
% rnd(i)=xor(xor(m_register(2)*F(2),m_register(3)*F(3)),m_register(4)*F(4));
% for j=2:4
% newregister(j)=xor(xor(m_register(j-1),d(j)*cell(j)),d(j)*m_register(4));
% newcell(j)=xor(xor(m_register(j-1)*cell(j),cell(j)*m_register(4)),m_register(j-1)*m_register(4));
%end
%m_register= newregister;
%cell=newcell;
%cell(2)=0;
%end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -