S盒及差分分析1作业:实现s盒的内部加密,对比s盒输入输出异或并完成分布表格2用到的知识:差分分析的基本思想是通过分析特定明文差对结果密文差的影响来获得可能性最大的密钥。对于s盒,任给输入异或,可以计算出相应输出异或,取值有16种可能,但不会取到所有值,而这些分布的不均匀性将恰是我们实现差分攻击的基础。3完成本次作业的体会:(1)要深刻的理解des和差分攻击的内涵并能够用尽量简洁的代码表现出来(2)在手动操作工作量最少的情况下完成任务,是我们追求的目标,思考要深入,编程要熟练。(3)理论联系实践,利用网络资源,吸取先进的经验方法。编程中,我遇到了“异或运算”的实现,在课本中,我们知道两个2进制数的异或运算通过“modulo2”运算来实现,但在查阅了资料后,发现了(a!=b)这样的运算,简化了代码和计算机的计算。4得到的结果:(1)输入任意的异或值,比如110100,100111和010101我们就可以得到对应该输入异或的输出异或。(2)统计以上表格可得到输入异或110100100111010101输出异或011100110011000100100010110111110111100011111111100001110010000111010010001001000010001111010111011110000010001011010111000100010010001111010111110100100010010011010111000100010111100000100010001000101101111101110011001100011000011100100001011110001111111111001000110000010001011011100000010101011110000000101011110011001101110110011111110100001001010010001001111100000000100111011011000011100110000100011100100011001100110010110010000011100101010101001001000011011111100111011101101111011001000000001111100110000010011011110011011101000111111000011110011101010010100011011000010001111110011101100010001111111000001010001101111000010101011101110110111110111011011100111110101100011011100110000010101111010111101111100011011001111011111100101000110110110001101110011011输出异或可能的输入(个数)1101001001110101010000010000018440010162600116040100222010104201100240111120101000646100108210100001011041011000801101884111004611116445程序代码:#includeiostream.h#includestring.h#includemath.hintS1[4][16]={{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}};voidmain(){inti=0,j=0,k=0;coutpleaseinputtheINPUT_XOR\n;intINPUT_XOR[6]={0};for(i=0;i=5;i++)cinINPUT_XOR[i];intI[64][6];for(i=0;i=63;i++){inttemp=i;for(j=5;j=0;j--){I[i][j]=temp%2;temp/=2;}}intII[64][6];for(i=0;i=63;i++)for(j=0;j=5;j++)II[i][j]=(I[i][j]!=INPUT_XOR[j]);intOUTPUT_XOR[64][4]={0};for(i=0;i=63;i++){inta=0,b=0;a=I[i][0]*2+I[i][5];b=I[i][1]*8+I[i][2]*4+I[i][3]*2+I[i][4];intR1[4];intT1=S1[a][b];for(j=3;j=0;j--){R1[j]=T1%2;T1/=2;}a=II[i][0]*2+II[i][5];b=II[i][1]*8+II[i][2]*4+II[i][3]*2+II[i][4];intR2[4];intT2=S1[a][b];for(j=3;j=0;j--){R2[j]=T2%2;T2/=2;}for(j=0;j=3;j++){OUTPUT_XOR[i][j]=(R1[j]!=R2[j]);coutOUTPUT_XOR[i][j];}cout\n;}}