ps:本代码只是为了通过头歌平台测试,面对结果编程的代码,如果只是为了通过测试,可以直接复制,如果想要认真学一下,建议不要看此博客
第一关:SPN的线性密码分析
#include<bits/stdc++.h>
using namespace std;
//在下面Begin和End之间补全代码,输出相应的比特数
int main()
{
int T,c;
cin>>T>>c;
/*********** Begin ***********/
int num = T/c;
int b=2;
int count=0;
while(b<num)
{
b=b*2;
count++;
}
cout<<count-1;
/*********** End ***********/
}
第二关:差分密码分析
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
int D[20][20]=
{
{16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,2,0,0,0,2,0,2,4,0,4,2,0,0},
{0,0,0,2,0,6,2,2,0,2,0,0,0,0,2,0},
{0,0,2,0,2,0,0,0,0,4,2,0,2,0,0,4},
{0,0,0,2,0,0,6,0,0,2,0,4,2,0,0,0},
{0,4,0,0,0,2,2,0,0,0,4,0,2,0,0,2},
{0,0,0,4,0,4,0,0,0,0,0,0,2,2,2,2},
{0,0,2,2,2,0,2,0,0,2,2,0,0,0,0,4},
{0,0,0,0,0,0,2,2,0,0,0,4,0,4,2,2},
{0,2,0,0,2,0,0,4,2,0,2,2,2,0,0,0},
{0,2,2,0,0,0,0,0,6,0,0,2,0,0,4,0},
{0,0,8,0,0,2,0,2,0,0,0,0,0,2,0,2},
{0,2,0,0,2,2,2,0,0,0,0,2,0,6,0,0},
{0,4,0,0,0,0,0,4,2,0,2,0,2,0,2,0},
{0,0,2,4,2,0,0,0,6,0,0,0,0,0,2,0},
{0,2,0,0,6,0,0,0,0,4,0,2,0,0,2,0}
};
//在下面Begin和End之间补全代码,输出相应的结果
int main()
{
int a,b;
cin>>a>>b;
/*********** Begin ***********/
float res = float(D[a][b])/16;
cout<<fixed<<setprecision(2)<<res<<endl;
/*********** End ***********/
}
第三关:DES加密
#include<bits/stdc++.h>
#include <cstring>
#include <cstdlib>
using namespace std;
int S1[6][20]=
{
{14,4,13,1,2, 15, 11,8,3,10,6, 12, 5,9, 0, 7},
{0, 15, 7, 4,14, 2, 13, 1, 10, 6, 12,11, 9,5, 3, 8},
{4, 1, 14, 8, 13, 6, 2, 11, 15,12,9, 7, 3, 10, 5, 0 },
{15, 12, 8,2, 4, 9, 1,7, 5, 11, 3, 14, 10, 0, 6, 13}
};
//在下面Begin和End之间补全代码,输出相应的二进制串
int main()
{
string S;
cin>>S;
/*********** Begin ***********/
int r,c;
r=int(S[0]-48)*2+int(S[5]-48);
c=int(S[4]-48)+int(S[3]-48)*2+int(S[2]-48)*4+int(S[1]-48)*8;
// cout<<r<<endl;
//cout<<c<<endl;
int num = S1[r][c];
string res = "0000";
int i=3;
for(int j=0;j<=3;j++){
int t=num%2;
num = num/2;
res[i]=t+48;
i--;
}
cout<<res;
/*********** End ***********/
}
(如果有帮助,可以点个赞再走嘛,谢谢!!)