📄 2.cpp
字号:
#include<iostream.h>
void cout1(int *a,int b)
{
for(int i = 0 ;i<b;i++)
{
cout<<a[i];
if(i !=b-1)
cout<<" ";
else cout<<endl;
}
}
int * jiao1 (int * a ,int i = 3)//二进制进行加1的运算
{
a[i] = a[i]++;
if(a[i] ==2 && i>=0)
{
a[i] = 0;
jiao1(a,--i);
}
return a;
}
int * XOR(int * a, int * b)// 四位二进制的数进行xor 运算
{
for(int i = 0; i<4 ; i++)
{
if( a[i] == b[i] )
a[i] = 0;
else
a[i] = 1;
}
return a;
}
int * s ( int * s,int *s0) // s0 是s盒子的值的变化字 s是输入的4bit的数
{ // 注意:s 是4位的,返回的结果是2位,所以,就只有2 3位有效
int a = s[0]*2 + s[1];
int b = s[2]*2 + s[3];
s[2]= s[3]=0;
for(int i = 0; i<s0[a*4+b]; i++)
jiao1(s);
return s;
}
int * fk(int * sw , int * k2)
{
int E_P [] = {4,1,2,3,2,3,4,1} ;
int s0 [] = {1,0,3,2,3,2,1,0,0,2,1,3,3,1,3,2};
int s1 [] = {0,1,2,3,2,0,1,3,3,0,1,0,2,1,0,3};
int p4 [] = {2,4,3,1};
int e_phou [8];
for(int i = 0;i<8;i++)
e_phou[i] = sw[E_P[i]+4-1];
cout<<1<<endl;
cout1(e_phou,8);
////////////////////////////////////////////////////////
XOR(e_phou,k2);
XOR(e_phou+4,k2+4);
cout<<2<<endl;
cout1(e_phou,8);
//////////////////////////////////////////////////////////
s(e_phou,s0);
cout1(e_phou+2,2);
s(e_phou+4,s1);
cout1(e_phou+6,2);
e_phou[4] = e_phou[2];
e_phou[5] = e_phou[3];// 4 5 6 7位为s0 和s1后的四个数
cout<<3<<endl;
cout1(e_phou+4,4);
/////////////////////////////////////////////////////////////
for(i = 0;i<4;i++)
e_phou[i] = e_phou[p4[i]+4-1];
// p4 后的四个数 0 1 2 3 中
cout<<4<<endl;
cout1(e_phou,8);
////////////////////////////////
XOR(sw ,e_phou);
cout<<5<<endl;
cout1(sw,8);
return sw;
}
//下面的函数是对求密匙的运算k1 k2
int *Ls_1(int * a)// 循环左移一位 , 是5为数的
{
int temp = a[0];
for(int i =0;i<4;i++)
a[i] = a[i+1];
a[4] = temp;
return a;
}
void main ()
{
// int s0 [] = {1,0,3,2,3,2,1,0,0,2,1,3,3,1,3,2};
// int s1 [] = {0,1,2,3,2,0,1,3,3,0,1,0,2,1,0,3};
int sw[8] = { 0,0,0,1,0,0,1,1};
int mishi[8] = {0,1,0,1,1,1,1,1};
fk(sw ,mishi);
/* s(a,s0);
cout1(a+2,2);
s(b,s1);
int a[4] ={0,1};
int b[4] ={0,1};
cout1(b+2,2);
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -