(最新版)密码学实验报告 下载本文

内容发布更新时间 : 2024/5/2 22:01:55星期一 下面是文章的全部内容请认真阅读。

{

key[i*8+j]=1; }

n=n/2; } }

swap(key,c,d);//种密钥置换1 for(i=0;i<16;i++) {

if(i==0||i==1||i==8||i==15)

{

move(c);//循环左移 move(d);//循环左移

}

else

{

move1(c); move1(d);

}

swap1(k,c,d);//置换2--得到k feistel(l,r,k,sbox);//feistel运算 }

for(i=0;i<32;i++) {

fei_result[i]=l[i]; fei_result[32+i]=r[i];

}//汇合feistel输出的l-16和r-16 ip1(fei_result,des);//进行ip逆置换 for(i=0;i<8;i++)

{

printf(\}

printf(\}

void ip(int ora_bit[],int l[],int r[])//ip置换 {

int i,j,k; int temp[8][8];

for(k=0,i=57;k<4,i<=63;k++,i+=2) {

temp[k][0]=ora_bit[i]; }

for(k=4,i=56;k<8,i<=62;i+=2,k++) {

temp[k][0]=ora_bit[i]; }

for(k=0,i=49;k<4,i<=55;k++,i+=2) {

temp[k][1]=ora_bit[i]; }

for(k=4,i=48;k<8,i<=54;i+=2,k++) {

temp[k][1]=ora_bit[i]; }

for(k=0,i=41;k<4,i<=47;k++,i+=2) {

temp[k][2]=ora_bit[i]; }

for(k=4,i=40;k<8,i<=46;i+=2,k++) {

temp[k][2]=ora_bit[i]; }

for(k=0,i=33;k<4,i<=39;k++,i+=2) {

temp[k][3]=ora_bit[i]; }

for(k=4,i=32;k<8,i<=38;i+=2,k++) {

temp[k][3]=ora_bit[i]; }

for(k=0,i=25;k<4,i<=31;k++,i+=2) {

temp[k][4]=ora_bit[i]; }

for(k=4,i=24;k<8,i<=30;i+=2,k++) {

temp[k][4]=ora_bit[i]; }

for(k=0,i=17;k<4,i<=23;k++,i+=2) {

temp[k][5]=ora_bit[i]; }

for(k=4,i=16;k<8,i<=22;i+=2,k++) {

temp[k][5]=ora_bit[i]; }

for(k=0,i=9;k<4,i<=15;k++,i+=2)

{

temp[k][6]=ora_bit[i]; }

for(k=4,i=8;k<8,i<=14;i+=2,k++) {

temp[k][6]=ora_bit[i]; }

for(k=0,i=1;k<4,i<=7;k++,i+=2) {

temp[k][7]=ora_bit[i]; }

for(k=4,i=0;k<8,i<=6;i+=2,k++) {

temp[k][7]=ora_bit[i]; }

for(i=0;i<4;i++) { }

for(i=4;i<8;i++) {

for(j=0;j<8;j++) }

{

r[(i-4)*8+j]=temp[i][j]; }

for(j=0;j<8;j++) {

l[i*8+j]=temp[i][j]; }

}

void swap(int key[],int c[],int d[])//置换选择1 {

c[0]=key[56]; c[1]=key[48]; c[2]=key[40]; c[3]=key[32]; c[4]=key[24]; c[5]=key[16]; c[6]=key[8]; c[7]=key[0]; c[8]=key[57]; c[9]=key[49]; c[10]=key[41]; c[11]=key[33]; c[12]=key[25]; c[13]=key[17]; c[14]=key[9]; c[15]=key[1]; c[16]=key[58]; c[17]=key[50]; c[18]=key[42]; c[19]=key[34]; c[20]=key[26]; c[21]=key[18]; c[22]=key[10]; c[23]=key[2]; c[24]=key[59]; c[25]=key[51];