欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

简单的des加密实现(C语言)

程序员文章站 2022-03-12 20:53:09
...

简单的des加密实现(C语言)

最近上完密码学的课,实验要求实现des加密,作为菜鸟参考了好多文章才写出来,记录一下
参考博客:
https://blog.csdn.net/m0_37962600/article/details/79912654
https://blog.csdn.net/qq_34838643/article/details/80007992
数据加密标准(Data Encryption Standard, DES)是迄今为止世界上最为广泛使用和流行的一种分组密码算法。
原理:该算法是一个利用56+8奇偶校验位(第8,16,24,32,40,48,56,64)=64位的**对以64位为单位的块数据进行加解密。
DES的框图如下
简单的des加密实现(C语言)
Des加密过程
(1) 对**进行处理

  1. 对**进行PC_1置换 64—>56
  2. 将的得到的结果分成左右(C0前28位,DO后28位)
  3. 按照循环左移表进行左移
  4. 再合并起来进行PC_2置换,得到16轮的子** 56—>48
    简单的des加密实现(C语言)
    (2)对明文的处理
    1.先对明文进行IP置换
    2.将结果分L,R(L前32位,R后32位)
    3.一轮迭代
    3.1对Ri-1进行扩展E进行运算 32—>48
    3.2与当前轮次的子**进行异或运算
    3.3再将结果送入s盒进行压缩 48—>32
    3.4进行P置换后,再与Li-1进行异或运算得到Ri
    3.5将Ri-1的值赋给Li
    (3)16轮后,将最后的得到的L,R左右调换位置
    再对其进行逆初始置换得到密文

)

简单的des加密实现(C语言)

S盒
输入S盒的数据为48位,将其6位为一组分为8组,分别对应8个S盒。6位中第1和第6位为一组组成一个两位的二进制数,转换为十进制作为行数,中间的4位构成4位二进制数,转换为十进制数作为列,然后查找对应的S盒找到对应的数,再将其转换为四位二进制数,即为S盒的输出。
简单的des加密实现(C语言)
简单的des加密实现(C语言)

解密过程
DES的解密算法与其加密算法使用的算法过程相同。两者的不同之处在于解密时子**Ki的使用顺序与加密时相反,如果子**为K1K2…K16,那么解密时子**的使用顺序为K16K15…K1,即使用DES解密算法进行解密时,将以64位密文作为输入,第1次迭代运算使用子**K16,第2次迭代运算使用子**K15,……,第16 次迭代使用子**K1,其它的运算与加密算法相同。这样,最后输出的是64位明文。
简单的des加密实现(C语言)
代码如下:

#include<stdio.h>
#include<string.h>
//IP置换
int IP[64] = { 58, 50, 42, 34, 26, 18, 10, 2,
             60, 52, 44, 36, 28, 20, 12, 4, 
			 62, 54, 46, 38, 30, 22, 14, 6, 
			 64, 56, 48, 40, 32, 24, 16, 8, 
			 57, 49, 41, 33, 25, 17,  9, 1, 
			 59, 51, 43, 35, 27, 19, 11, 3, 
			 61, 53, 45, 37, 29, 21, 13, 5, 
			 63, 55, 47, 39, 31, 23, 15, 7 
            }; 
//逆IP置换
int IP_1[64] = { 40, 8, 48, 16, 56, 24, 64, 32,
               39, 7, 47, 15, 55, 23, 63, 31, 
			   38, 6, 46, 14, 54, 22, 62, 30, 
			   37, 5, 45, 13, 53, 21, 61, 29, 
			   36, 4, 44, 12, 52, 20, 60, 28, 
			   35, 3, 43, 11, 51, 19, 59, 27, 
			   34, 2, 42, 10, 50, 18, 58, 26,
	           33, 1, 41, 9, 49, 17, 57, 25 }; 
//选择置换PC-1
int PC_1[56] = { 57, 49, 41, 33, 25, 17, 9, 1, 
               58,50, 42, 34, 26, 18, 10, 2, 
			   59, 51, 43, 35, 27, 19, 11, 3, 
			   60, 52, 44, 36, 63, 55, 47, 39, 
			   31, 23, 15, 7, 62, 54, 46, 38, 
			   30, 22, 14, 6, 61, 53, 45,  37, 
			   29, 21, 13, 5, 28, 20, 12, 4 };
//选择置换PC-2
int PC_2[48] = { 14, 17, 11, 24, 1, 5, 3, 28, 
               15,  6, 21, 10, 23, 19, 12, 
			   4, 26, 8, 16, 7, 27, 20, 13, 
			   2, 41, 52, 31, 37, 47, 55, 30,
			   40, 51, 45, 33, 48, 44, 49, 39, 
			   56, 34, 53, 46, 42, 50, 36,29, 32 }; //56->48
//扩展置换E
int E[48] = { 32, 1, 2, 3, 4, 5, 4, 5, 
             6, 7, 8, 9, 8, 9, 10, 11, 
			 12, 13, 12, 13, 14, 15, 16, 
			 17, 16, 17, 18, 19, 20, 21,
              20, 21, 22, 23, 24, 25, 24, 
			  25, 26, 27, 28, 29, 28, 29, 
			  30, 31, 32, 1 }; // 表3:32->48
//扩展置换P
int P[32] = { 16, 7, 20, 21, 29, 12, 28, 17,
             1, 15, 23, 26, 5, 18, 31, 10, 
			 2, 8, 24, 14, 32, 27, 3, 9, 
			 19, 13, 30, 6, 22,11, 4, 25 }; //表12:32
//S盒
int S_Box[8][65]=
{
    {
        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
    },
    {
        15,1,8,14,6,11,3,4,9,7,2,13,12,0,5,10,
        3,13,4,7,15,2,8,14,12,0,1,10,6,9,11,5,
        0,14,7,11,10,4,13,1,5,8,12,6,9,3,2,15,
        13,8,10,1,3,15,4,2,11,6,7,12,0,5,14,9
    },
    {
        10,0,9,14,6,3,15,5,1,13,12,7,11,4,2,8,
        13,7,0,9,3,4,6,10,2,8,5,14,12,11,15,1,
        13,6,4,9,8,15,3,0,11,1,2,12,5,10,14,7,
        1,10,13,0,6,9,8,7,4,15,14,3,11,5,2,12
    },
    {
        7,13,14,3,0,6,9,10,1,2,8,5,11,12,4,15,
        13,8,11,5,6,15,0,3,4,7,2,12,1,10,14,9,
        10,6,9,0,12,11,7,13,15,1,3,14,5,2,8,4,
        3,15,0,6,10,1,13,8,9,4,5,11,12,7,2,14
    },
    {
        2,12,4,1,7,10,11,6,8,5,3,15,13,0,14,9,
        14,11,2,12,4,7,13,1,5,0,15,10,3,9,8,6,
        4,2,1,11,10,13,7,8,15,9,12,5,6,3,0,14,
        11,8,12,7,1,14,2,13,6,15,0,9,10,4,5,3
    },
    {
        12,1,10,15,9,2,6,8,0,13,3,4,14,7,5,11,
        10,15,4,2,7,12,9,5,6,1,13,14,0,11,3,8,
        9,14,15,5,2,8,12,3,7,0,4,10,1,13,11,6,
        4,3,2,12,9,5,15,10,11,14,1,7,6,0,8,13
    },
    {
        4,11,2,14,15,0,8,13,3,12,9,7,5,10,6,1,
        13,0,11,7,4,9,1,10,14,3,5,12,2,15,8,6,
        1,4,11,13,12,3,7,14,10,15,6,8,0,5,9,2,
        6,11,13,8,1,4,10,7,9,5,0,15,14,2,3,12
    },
    {
        13,2,8,4,6,15,11,1,10,9,3,14,5,0,12,7,
        1,15,13,8,10,3,7,4,12,5,6,11,0,14,9,2,
        7,11,4,1,9,12,14,2,0,6,10,13,15,3,5,8,
        2,1,14,7,4,10,8,13,15,12,9,0,3,5,6,11
    }
};
//左移位数
int LeftMove[16]={ 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2,2, 2, 2, 2, 1 }; // 表15:左移位置列表

/*****************************************************************/

//置换函数
void zhihuan(int *k1, int *k2,int n,int *rule)
{
    int i, j;  
 for (i=0; i < n; i++)
 {
   j =rule[i]; //根据rule数组进行置换,也就是赋值
   k2[i] = k1[j-1];
 }
}
//循环左移函数
void shift(int *k1,int *k2,int n,int s)
{
    int i=0;
	for (i=0;i<n;i++)
	{
		k2[i]=k1[(s+i)%n];  //利用取余实现左移
	}	
}
//按位异或函数
void XOR(int *k1,int *k2,int n,int *k3)
{
	int i=0;
	for(i=0;i<n;i++)
	{
	   if(k1[i]==k2[i])  //异或
		   k3[i]=0;
	   else
		   k3[i]=1;
	}
}
//**加密函数
void  subkey(int *k, int (*k2)[48])
{
	int  i=0,j=0;
	int out[56]={0},C[28]={0},D[28]={0},e[28]={0},t[56]={0};
	zhihuan(k, out ,56,PC_1);
	for(i=0;i<28;i++)
	{
		C[i]=out[i];        //C0
		D[i]=out[i+28];    //D0
	}
 for(j=0; j<16; j++)
    {
        shift(C,e,28,LeftMove[j]);  //循环左移
        for(i=0;i<28;i++)
		{
			C[i]=e[i];	       //Cj
		}   
        shift(D,e,28,LeftMove[j]);
         for(i=0;i<28;i++)
		{
			D[i]=e[i];	      //Dj
		}                                  
        for(i=0;i<28;i++)
		{
			t[i]=C[i];
			t[i+28]=D[i];	
		}
        zhihuan(t,*(k2+j),48,PC_2);//置换选择2,得到Kj
	   }
}
//轮函数
void jiami(int *L,int *R,int *sk,int t)
{ 
	int i=0,j=0,k=0,m=0;
	int row=0,col=0;
	int out1[49]= {0},out2[49]= {0},out3[33]= {0},out4[33]= {0},temp[33]= {0};
    printf("K%d=",t+1);
     for(k=0;k<48;k++)
	{
	  printf("%d",sk[k]);
	}
	 printf("\n");
    zhihuan(R,out1,48, E);  //扩展置换E
    printf("扩展置换E(R%d)=",t);
    for(i=0;i<48;i++)
	 {
	  printf("%d",out1[i]);
	 }
	 printf("\n");
    XOR(out1,sk,48,out2);      //与子**异或
    printf("与子**异或后R%d=",t,t+1);
     for(k=0;k<48;k++)
	{
	  printf("%d",out2[k]);
	}
	 printf("\n");
	for(i=0; i<8; i++)           //S盒代换
    {
        row = (out2[i*6]*2)+(out2[i*6+5]*1);   //第1,6位组成行号
        col = (out2[i*6+1]*8)+(out2[i*6+2]*4)+(out2[i*6+3]*2)+(out2[i*6+4]*1);  //第2,3,4,5位组成列号
		m=S_Box[i][row*16+col];
		for(j=3;j>=0;j--)                 //十进制转换二进制
	   {
        out3[i*4+j]=m%2;
         m/=2;
       }
	}
	printf("%d轮S盒输出=",t+1);
	 for(k=0;k<32;k++)
	{
	  printf("%d",out3[k]);
	}
	 printf("\n");
	zhihuan(out3,out4,32,P);        //P置换
	printf("P置换R%d=",t);
    for(k=0;k<32;k++)
	{
	  printf("%d",out4[k]);
	}
	printf("\n");
	for(i=0;i<32;i++)
	{
		temp[i]=R[i];   //保存旧的R
	} 
	XOR(L,out4,32,R);  //更新R  与L异或
    printf("R%d=",t+1);
     for(k=0;k<32;k++)
	{
	  printf("%d",R[k]);
	}
	printf("\n");
  	for(i=0;i<32;i++)
	{
		L[i]=temp[i];   //将R赋予L
	}
	 printf("L%d=",t+1);
	 for(k=0;k<32;k++)
	{
	  printf("%d",L[k]);
	}
  }
/*主函数*/
int main()
{
 int i=0;
 int output[64]={0};
 int keybox[16][48]={0};        //加密后的**
 int input[64]={0,0,0,0,0,0,0,1,    //明文
                0,0,1,0,0,0,1,1, 
                0,1,0,0,0,1,0,1, 
                0,1,1,0,0,1,1,1,
                1,0,0,0,1,0,0,1, 
                1,0,1,0,1,0,1,1, 
                1,1,0,0,1,1,0,1, 
                1,1,1,0,1,1,1,1};
int key[64]=   {0,0,0,1,0,0,1,1,
				0,0,1,1,0,1,0,0,
				0,1,0,1,0,1,1,1,
				0,1,1,1,1,0,0,1,
				1,0,0,1,1,0,1,1,
				1,0,1,1,1,1,0,0,
				1,1,0,1,1,1,1,1,
				1,1,1,1,0,0,0,1};

int out[65]={0},L[33]={0},R[33]={0},cipher[65]={0};
 subkey(key,keybox); 产生16***
 printf("***************************加密过程*********************************/\n\n");
 /*******************************
          加密过程
 /******************************/
 zhihuan(input,output,64,IP);  //明文初始置换
 printf("IP置换:");
 for(i=0;i<64;i++)
 {
  printf("%d",output[i]);   //输出IP置换
 }
 for(i=0;i<32;i++)          //分为R,L
	{
	 L[i]=output[i];          
	 R[i]=output[i+32];
    } 
	 
 for(i=0; i<16; i++)
    {
        printf("\n-------------------------------第%d轮------------------------------------\n"
,i+1);
        jiami(L,R,*(keybox+i),i);
    }
  for(i=0;i<32;i++)
	{
	 output[i+32]=L[i];
	 output[i]=R[i];
    } 
     zhihuan(output,cipher,64,IP_1);
	 printf("\n密文:");
	 for(i=0;i<64;i++)
	{
	  printf("%d",cipher[i]);
	}
	 printf("\n\n\n");
printf("/***************************解密过程********************************/\n\n");
/*************************************************
                    解密过程
/****************************************************/
 for(i=0;i<64;i++)
 {
  input[i]=cipher[i];       //将上一轮的密文赋给input
 }
 zhihuan(input,output,64,IP);  //密文初始置换
 printf("IP置换:");
 for(i=0;i<64;i++)
 {
  printf("%d",output[i]);   //IP置换
 }
 for(i=0;i<32;i++)          //分为R,L
	{
	 L[i]=output[i];          
	 R[i]=output[i+32];
    } 
	 
 for(i=0; i<16; i++)
    {
        printf("\n-------------------------------第%d轮------------------------------------\n"
,i+1);
        jiami(L,R,*(keybox+15-i),i);
    }
  for(i=0;i<32;i++)
	{
	 output[i+32]=L[i];
	 output[i]=R[i];
    } 
     zhihuan(output,cipher,64,IP_1);
	 printf("\n解密的明文为 :");
	 for(i=0;i<64;i++)
	{
	  printf("%d",cipher[i]);
	}
 printf("\n");
	 return 0;
   }

运行结果如下:

***************************加密过程*********************************/

IP置换:1100110000000000110011001111111111110000101010101111000010101010
-------------------------------第1轮------------------------------------
K1=000110110000001011101111111111000111000001110010
扩展置换E(R0)=011110100001010101010101011110100001010101010101
与子**异或后R0=011000010001011110111010100001100110010100100111
1轮S盒输出=01011100100000101011010110010111
P置换R0=00100011010010101010100110111011
R1=11101111010010100110010101000100
L1=11110000101010101111000010101010
-------------------------------第2轮------------------------------------
K2=011110011010111011011001110110111100100111100101
扩展置换E(R1)=011101011110101001010100001100001010101000001001
与子**异或后R1=000011000100010010001101111010110110001111101100
2轮S盒输出=11111000110100000011101010101110
P置换R1=00111100101010111000011110100011
R2=11001100000000010111011100001001
L2=11101111010010100110010101000100
-------------------------------第3轮------------------------------------
K3=010101011111110010001010010000101100111110011001
扩展置换E(R2)=111001011000000000000010101110101110100001010011
与子**异或后R2=101100000111110010001000111110000010011111001010
3轮S盒输出=00100111000100001110000101101111
P置换R2=01001101000101100110111010110000
R3=10100010010111000000101111110100
L3=11001100000000010111011100001001
-------------------------------第4轮------------------------------------
K4=011100101010110111010110110110110011010100011101
扩展置换E(R3)=010100000100001011111000000001010111111110101001
与子**异或后R3=001000101110111100101110110111100100101010110100
4轮S盒输出=00100001111011011001111100111010
P置换R3=10111011001000110111011101001100
R4=01110111001000100000000001000101
L4=10100010010111000000101111110100
-------------------------------第5轮------------------------------------
K5=011111001110110000000111111010110101001110101000
扩展置换E(R4)=101110101110100100000100000000000000001000001010
与子**异或后R4=110001100000010100000011111010110101000110100010
5轮S盒输出=01010000110010000011000111101011
P置换R4=00101000000100111010110111000011
R5=10001010010011111010011000110111
L5=01110111001000100000000001000101
-------------------------------第6轮------------------------------------
K6=011000111010010100111110010100000111101100101111
扩展置换E(R5)=110001010100001001011111110100001100000110101111
与子**异或后R5=101001101110011101100001100000001011101010000000
6轮S盒输出=01000001111100110100110000111101
P置换R5=10011110010001011100110100101100
R6=11101001011001111100110101101001
L6=10001010010011111010011000110111
-------------------------------第7轮------------------------------------
K7=111011001000010010110111111101100001100010111100
扩展置换E(R6)=111101010010101100001111111001011010101101010011
与子**异或后R6=000110011010111110111000000100111011001111101111
7轮S盒输出=00010000011101010100000010101101
P置换R6=10001100000001010001110000100111
R7=00000110010010101011101000010000
L7=11101001011001111100110101101001
-------------------------------第8轮------------------------------------
K8=111101111000101000111010110000010011101111111011
扩展置换E(R7)=000000001100001001010101010111110100000010100000
与子**异或后R7=111101110100100001101111100111100111101101011011
8轮S盒输出=01101100000110000111110010101110
P置换R7=00111100000011101000011011111001
R8=11010101011010010100101110010000
L8=00000110010010101011101000010000
-------------------------------第9轮------------------------------------
K9=111000001101101111101011111011011110011110000001
扩展置换E(R8)=011010101010101101010010101001010111110010100001
与子**异或后R8=100010100111000010111001010010001001101100100000
9轮S盒输出=00010001000011000101011101110111
P置换R8=00100010001101100111110001101010
R9=00100100011111001100011001111010
L9=11010101011010010100101110010000
-------------------------------第10轮------------------------------------
K10=101100011111001101000111101110100100011001001111
扩展置换E(R9)=000100001000001111111001011000001100001111110100
与子**异或后R9=101000010111000010111110110110101000010110111011
10轮S盒输出=11011010000001000101001001110101
P置换R9=01100010101111001001110000100010
R10=10110111110101011101011110110010
L10=00100100011111001100011001111010
-------------------------------第11轮------------------------------------
K11=001000010101111111010011110111101101001110000110
扩展置换E(R10)=010110101111111010101011111010101111110110100101
与子**异或后R10=011110111010000101111000001101000010111000100011
11轮S盒输出=01110011000001011101000100000001
P置换R10=11100001000001001111101000000010
R11=11000101011110000011110001111000
L11=10110111110101011101011110110010
-------------------------------第12轮------------------------------------
K12=011101010111000111110101100101000110011111101001
扩展置换E(R11)=011000001010101111110000000111111000001111110001
与子**异或后R11=000101011101101000000101100010111110010000011000
12轮S盒输出=01111011100010110010011000110101
P置换R11=11000010011010001100111111101010
R12=01110101101111010001100001011000
L12=11000101011110000011110001111000
-------------------------------第13轮------------------------------------
K13=100101111100010111010001111110101011101001000001
扩展置换E(R12)=001110101011110111111010100011110000001011110000
与子**异或后R12=101011010111100000101011011101011011100010110001
13轮S盒输出=10011010110100011000101101001111
P置换R12=11011101101110110010100100100010
R13=00011000110000110001010101011010
L13=01110101101111010001100001011000
-------------------------------第14轮------------------------------------
K14=010111110100001110110111111100101110011100111010
扩展置换E(R13)=000011110001011000000110100010101010101011110100
与子**异或后R13=010100000101010110110001011110000100110111001110
14轮S盒输出=01100100011110011001101011110001
P置换R13=10110111001100011000111001010101
R14=11000010100011001001011000001101
L14=00011000110000110001010101011010
-------------------------------第15轮------------------------------------
K15=101111111001000110001101001111010011111100001010
扩展置换E(R14)=111000000101010001011001010010101100000001011011
与子**异或后R14=010111111100010111010100011101111111111101010001
15轮S盒输出=10110010111010001000110100111100
P置换R14=01011011100000010010011101101110
R15=01000011010000100011001000110100
L15=11000010100011001001011000001101
-------------------------------第16轮------------------------------------
K16=110010110011110110001011000011100001011111110101
扩展置换E(R15)=001000000110101000000100000110100100000110101000
与子**异或后R15=111010110101011110001111000101000101011001011101
16轮S盒输出=10100111100000110010010000101001
P置换R15=11001000110000000100111110011000
R16=00001010010011001101100110010101
L16=01000011010000100011001000110100
密文:1000010111101000000100110101010000001111000010101011010000000101


/***************************解密过程********************************/

IP置换:0000101001001100110110011001010101000011010000100011001000110100
-------------------------------第1轮------------------------------------
K1=110010110011110110001011000011100001011111110101
扩展置换E(R0)=001000000110101000000100000110100100000110101000
与子**异或后R0=111010110101011110001111000101000101011001011101
1轮S盒输出=10100111100000110010010000101001
P置换R0=11001000110000000100111110011000
R1=11000010100011001001011000001101
L1=01000011010000100011001000110100
-------------------------------第2轮------------------------------------
K2=101111111001000110001101001111010011111100001010
扩展置换E(R1)=111000000101010001011001010010101100000001011011
与子**异或后R1=010111111100010111010100011101111111111101010001
2轮S盒输出=10110010111010001000110100111100
P置换R1=01011011100000010010011101101110
R2=00011000110000110001010101011010
L2=11000010100011001001011000001101
-------------------------------第3轮------------------------------------
K3=010111110100001110110111111100101110011100111010
扩展置换E(R2)=000011110001011000000110100010101010101011110100
与子**异或后R2=010100000101010110110001011110000100110111001110
3轮S盒输出=01100100011110011001101011110001
P置换R2=10110111001100011000111001010101
R3=01110101101111010001100001011000
L3=00011000110000110001010101011010
-------------------------------第4轮------------------------------------
K4=100101111100010111010001111110101011101001000001
扩展置换E(R3)=001110101011110111111010100011110000001011110000
与子**异或后R3=101011010111100000101011011101011011100010110001
4轮S盒输出=10011010110100011000101101001111
P置换R3=11011101101110110010100100100010
R4=11000101011110000011110001111000
L4=01110101101111010001100001011000
-------------------------------第5轮------------------------------------
K5=011101010111000111110101100101000110011111101001
扩展置换E(R4)=011000001010101111110000000111111000001111110001
与子**异或后R4=000101011101101000000101100010111110010000011000
5轮S盒输出=01111011100010110010011000110101
P置换R4=11000010011010001100111111101010
R5=10110111110101011101011110110010
L5=11000101011110000011110001111000
-------------------------------第6轮------------------------------------
K6=001000010101111111010011110111101101001110000110
扩展置换E(R5)=010110101111111010101011111010101111110110100101
与子**异或后R5=011110111010000101111000001101000010111000100011
6轮S盒输出=01110011000001011101000100000001
P置换R5=11100001000001001111101000000010
R6=00100100011111001100011001111010
L6=10110111110101011101011110110010
-------------------------------第7轮------------------------------------
K7=101100011111001101000111101110100100011001001111
扩展置换E(R6)=000100001000001111111001011000001100001111110100
与子**异或后R6=101000010111000010111110110110101000010110111011
7轮S盒输出=11011010000001000101001001110101
P置换R6=01100010101111001001110000100010
R7=11010101011010010100101110010000
L7=00100100011111001100011001111010
-------------------------------第8轮------------------------------------
K8=111000001101101111101011111011011110011110000001
扩展置换E(R7)=011010101010101101010010101001010111110010100001
与子**异或后R7=100010100111000010111001010010001001101100100000
8轮S盒输出=00010001000011000101011101110111
P置换R7=00100010001101100111110001101010
R8=00000110010010101011101000010000
L8=11010101011010010100101110010000
-------------------------------第9轮------------------------------------
K9=111101111000101000111010110000010011101111111011
扩展置换E(R8)=000000001100001001010101010111110100000010100000
与子**异或后R8=111101110100100001101111100111100111101101011011
9轮S盒输出=01101100000110000111110010101110
P置换R8=00111100000011101000011011111001
R9=11101001011001111100110101101001
L9=00000110010010101011101000010000
-------------------------------第10轮------------------------------------
K10=111011001000010010110111111101100001100010111100
扩展置换E(R9)=111101010010101100001111111001011010101101010011
与子**异或后R9=000110011010111110111000000100111011001111101111
10轮S盒输出=00010000011101010100000010101101
P置换R9=10001100000001010001110000100111
R10=10001010010011111010011000110111
L10=11101001011001111100110101101001
-------------------------------第11轮------------------------------------
K11=011000111010010100111110010100000111101100101111
扩展置换E(R10)=110001010100001001011111110100001100000110101111
与子**异或后R10=101001101110011101100001100000001011101010000000
11轮S盒输出=01000001111100110100110000111101
P置换R10=10011110010001011100110100101100
R11=01110111001000100000000001000101
L11=10001010010011111010011000110111
-------------------------------第12轮------------------------------------
K12=011111001110110000000111111010110101001110101000
扩展置换E(R11)=101110101110100100000100000000000000001000001010
与子**异或后R11=110001100000010100000011111010110101000110100010
12轮S盒输出=01010000110010000011000111101011
P置换R11=00101000000100111010110111000011
R12=10100010010111000000101111110100
L12=01110111001000100000000001000101
-------------------------------第13轮------------------------------------
K13=011100101010110111010110110110110011010100011101
扩展置换E(R12)=010100000100001011111000000001010111111110101001
与子**异或后R12=001000101110111100101110110111100100101010110100
13轮S盒输出=00100001111011011001111100111010
P置换R12=10111011001000110111011101001100
R13=11001100000000010111011100001001
L13=10100010010111000000101111110100
-------------------------------第14轮------------------------------------
K14=010101011111110010001010010000101100111110011001
扩展置换E(R13)=111001011000000000000010101110101110100001010011
与子**异或后R13=101100000111110010001000111110000010011111001010
14轮S盒输出=00100111000100001110000101101111
P置换R13=01001101000101100110111010110000
R14=11101111010010100110010101000100
L14=11001100000000010111011100001001
-------------------------------第15轮------------------------------------
K15=011110011010111011011001110110111100100111100101
扩展置换E(R14)=011101011110101001010100001100001010101000001001
与子**异或后R14=000011000100010010001101111010110110001111101100
15轮S盒输出=11111000110100000011101010101110
P置换R14=00111100101010111000011110100011
R15=11110000101010101111000010101010
L15=11101111010010100110010101000100
-------------------------------第16轮------------------------------------
K16=000110110000001011101111111111000111000001110010
扩展置换E(R15)=011110100001010101010101011110100001010101010101
与子**异或后R15=011000010001011110111010100001100110010100100111
16轮S盒输出=01011100100000101011010110010111
P置换R15=00100011010010101010100110111011
R16=11001100000000001100110011111111
L16=11110000101010101111000010101010
解密的明文为 :0000000100100011010001010110011110001001101010111100110111101111
Press any key to continue

参考博客:
https://blog.csdn.net/m0_37962600/article/details/79912654
https://blog.csdn.net/qq_34838643/article/details/80007992