📄 df.cpp
字号:
#include<iostream>
using namespace std;
void shift(int R1[20],int R2[23],int R3[24],int r)
{
int j,R0;
if(r==1)
{
R0=R1[13]^R1[16]^R1[17]^R1[18];
for(j=18;j>=0;j--)
R1[j+1]=R1[j];
R1[0]=R0;
}
else if(r==2)
{
R0=R2[20]^R2[21];
for(j=21;j>=0;j--)
R2[j+1]=R2[j];
R2[0]=R0;
}
else if(r==3)
{
R0=R3[7]^R3[20]^R3[21]^R3[22];
for(j=22;j>=0;j--)
R3[j+1]=R3[j];
R3[0]=R0;
}
}
void beginning(int R1[20],int R2[23],int R3[24],int key[64])
{
int Q,i;
for(i=0;i<64;i++)
{
R1[0]=R1[0]^key[i];
R2[0]=R2[0]^key[i];
R3[0]=R3[0]^key[i];
Q=R1[18]^R2[21]^R3[22];
shift(R1,R2,R3,1);
shift(R1,R2,R3,2);
shift(R1,R2,R3,3);
cout<<Q;
}
}
void LSFR(int R1[20],int R2[23],int R3[24],int f[22])
{
int Q;
for(int i=0;i<22;i++)
{
R1[0]=R1[0]^f[i];
R2[0]=R2[0]^f[i];
R3[0]=R3[0]^f[i];
Q=R1[18]^R2[21]^R3[22];
shift(R1,R2,R3,1);
shift(R1,R2,R3,2);
shift(R1,R2,R3,3);
cout<<Q;
}
}
void clock(int R1[20],int R2[23],int R3[24])
{
int Q,R0;
R0=(R1[9]&R2[11])^(R2[11]&R3[11])^(R1[9]&R3[11]);
if((R1[9]==R0)&&(R2[11]==R0)&&(R3[11]==R0))
{
shift(R1,R2,R3,1);
shift(R1,R2,R3,2);
shift(R1,R2,R3,3);
}
else if((R2[11]==R0)&&(R1[9]==R0))
{
shift(R1,R2,R3,1);
shift(R1,R2,R3,2);
}
else if((R3[11]==R0)&&(R1[9]==R0))
{
shift(R1,R2,R3,1);
shift(R1,R2,R3,3);
}
else if((R3[11]==R0)&&(R2[11]==R0))
{
shift(R1,R2,R3,2);
shift(R1,R2,R3,3);
}
Q=R1[19]^R2[22]^R3[23];
cout<<Q;
}
void main()
{
int R1[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int R2[23]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int R3[24]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int key[64]={0,1,0,0,1,0,0,0,1,1,0,0,0,1,0,0,1,0,1,0,0,0,1,0,1,1,1,0,0,1,1,0,
1,0,0,1,0,0,0,1,1,1,0,1,0,1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,0,1,1,1};
int Frame_number[22]={0,0,1,0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0};
int i;
beginning(R1,R2,R3,key);
cout<<endl;
LSFR(R1,R2,R3,Frame_number);
cout<<endl;
cout<<"被丢弃的100位输出依次是:"<<endl;
for(i=0;i<100;i++)
clock(R1,R2,R3);
cout<<endl;
cout<<"第一个114位输出依次是:"<<endl;
for(i=100;i<214;i++)
clock(R1,R2,R3);
cout<<endl;
cout<<"第二个114位输出依次是:"<<endl;
for(i=214;i<328;i++)
clock(R1,R2,R3);
cout<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -