⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 des.lst

📁 c51写的DES加解密程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V6.12  DES                                                                    01/17/2003 18:27:26 PAGE 1   


C51 COMPILER V6.12, COMPILATION OF MODULE DES
OBJECT MODULE PLACED IN .\DES.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\DES.c LARGE DEBUG OBJECTEXTEND

stmt level    source

   1          /*
   2           * 重新安排S-box中数据顺序,如果输入的六位是000101,按DES标准的查询方式则是
   3           * 查第二行中的第三列数据。而此表中因为"000101"=5,则是查第六个数据得到"7"
   4           */
   5          static unsigned char SBox_1[64]={
   6          	14,0,4,15,13,7,1,4,
   7              2,14,15,2,11,13,8,1,
   8              3,10,10,6,6,12,12,11,
   9              5,9,9,5,0,3,7,8,
  10              4,15,1,12,14,8,8,2,
  11              13,4,6,9,2,1,11,7,
  12              15,5,12,11,9,3,7,14,
  13              3,10,10,0,5,6,0,13
  14          };
  15          static unsigned char SBox_2[64]={
  16          	15,3,1,13,8,4,14,7,
  17              6,15,11,2,3,8,4,14,
  18              9,12,7,0,2,1,13,10,
  19              12,6,0,9,5,11,10,5,
  20              0,13,14,8,7,10,11,1,
  21              10,3,4,15,13,4,1,2,
  22              5,11,8,6,12,7,6,12,
  23              9,0,3,5,2,14,15,9
  24          };
  25          static unsigned char SBox_3[64]={
  26          	10,13,0,7,9,0,14,9,
  27              6,3,3,4,15,6,5,10,
  28              1,2,13,8,12,5,7,14,
  29              11,12,4,11,2,15,8,1,
  30              13,1,6,10,4,13,9,0,
  31              8,6,15,9,3,8,0,7,
  32              11,4,1,15,2,14,12,3,
  33              5,11,10,5,14,2,7,12
  34          };
  35          static unsigned char SBox_4[64]={
  36           	7,13,13,8,14,11,3,5,
  37              0,6,6,15,9,0,10,3,
  38              1,4,2,7,8,2,5,12,
  39              11,1,12,10,4,14,15,9,
  40              10,3,6,15,9,0,0,6,
  41              12,10,11,1,7,13,13,8,
  42              15,9,1,4,3,5,14,11,
  43              5,12,2,7,8,2,4,14
  44          };
  45          static unsigned char SBox_5[64]={
  46           	2,14,12,11,4,2,1,12,
  47              7,4,10,7,11,13,6,1,
  48              8,5,5,0,3,15,15,10,
  49              13,3,0,9,14,8,9,6,
  50              4,11,2,8,1,12,11,7,
  51              10,1,13,14,7,2,8,13,
  52              15,6,9,15,12,0,5,9,
  53              6,10,3,4,0,5,14,3
  54          };
  55          static unsigned char SBox_6[64]={
C51 COMPILER V6.12  DES                                                                    01/17/2003 18:27:26 PAGE 2   

  56           	12,10,1,15,10,4,15,2,
  57              9,7,2,12,6,9,8,5,
  58              0,6,13,1,3,13,4,14,
  59              14,0,7,11,5,3,11,8,
  60              9,4,14,3,15,2,5,12,
  61              2,9,8,5,12,15,3,10,
  62              7,11,0,14,4,1,10,7,
  63              1,6,13,0,11,8,6,13
  64          };
  65          static unsigned char SBox_7[64]={
  66           	4,13,11,0,2,11,14,7,
  67              15,4,0,9,8,1,13,10,
  68              3,14,12,3,9,5,7,12,
  69              5,2,10,15,6,8,1,6,
  70              1,6,4,11,11,13,13,8,
  71              12,1,3,4,7,10,14,7,
  72              10,9,15,5,6,0,8,15,
  73              0,14,5,2,9,3,2,12
  74          };
  75          static unsigned char SBox_8[64]={
  76           	13,1,2,15,8,13,4,8,
  77              6,10,15,3,11,7,1,4,
  78              10,12,9,5,3,6,14,11,
  79              5,0,0,14,12,9,7,2,
  80              7,2,11,1,4,14,1,7,
  81              9,4,12,10,14,8,2,13,
  82              0,15,6,12,10,9,13,0,
  83              15,3,3,5,5,6,8,11
  84          };
  85          
  86          /*
  87           * 0(行)   57,49,41,33,25,17, 9, 1,
  88           * 1       58,50,42,34,26,18,10, 2,
  89           * 2       59,51,43,35,27,19,11, 3,
  90           * 3       60,52,44,36,63,55,47,39,
  91           * 4       31,23,15, 7,62,54,46,38,
  92           * 5       30,22,14, 6,61,53,45,37,
  93           * 6       29,21,13, 5,28,20,12, 4
  94           *  譬如1换到了第8位,在下面的数组中表示为是{0x00,0x01},0x00表示与新key数组中的
  95           *  第"0"号key或运算,当然或上的是"0x01",即key[0x00] |= 0x01
  96           *  转换算法中将采用左移位运算,每移一位则在下表中查询是否应“或”操作key数组中
  97           *  的某一个key
  98           */
  99          static unsigned char Key_64_To_56_Tab[64][2]={
 100          	{0x00,0x01},	// 1
 101              {0x01,0x01},	// 2
 102              {0x02,0x01},	// 3
 103              {0x06,0x01},	// 4
 104              {0x06,0x10},	// 5
 105              {0x05,0x10},	// 6
 106              {0x04,0x10},	// 7
 107              {0x00,0x00},	// 8	no use
 108          
 109              {0x00,0x02},	// 9
 110              {0x01,0x02},	// 10
 111              {0x02,0x02},	// 11
 112              {0x06,0x02},	// 12
 113              {0x06,0x20},	// 13
 114              {0x05,0x20},	// 14
 115              {0x04,0x20},	// 15
 116              {0x00,0x00},	// 16
 117          
C51 COMPILER V6.12  DES                                                                    01/17/2003 18:27:26 PAGE 3   

 118              {0x00,0x04},	// 17
 119              {0x01,0x04},	// 18
 120          	{0x02,0x04},	// 19
 121              {0x06,0x04},	// 20
 122              {0x06,0x40},	// 21
 123              {0x05,0x40},	// 22
 124              {0x04,0x40},	// 23
 125              {0x00,0x00},	// 24
 126          
 127              {0x00,0x08},	// 25
 128              {0x01,0x08},	// 26
 129              {0x02,0x08},	// 27
 130          	{0x06,0x08},	// 28
 131              {0x06,0x80},	// 29
 132              {0x05,0x80},	// 30
 133              {0x04,0x80},	// 31
 134              {0x00,0x00},	// 32
 135          
 136              {0x00,0x10},	// 33
 137              {0x01,0x10},	// 34
 138              {0x02,0x10},	// 35
 139              {0x03,0x10},	// 36
 140              {0x05,0x01},	// 37
 141              {0x04,0x01},	// 38
 142              {0x03,0x01},	// 39
 143          	{0x00,0x00},	// 40
 144          
 145              {0x00,0x20},	// 41
 146              {0x01,0x20},	// 42
 147              {0x02,0x20},	// 43
 148              {0x03,0x20},	// 44
 149              {0x05,0x02},	// 45
 150              {0x04,0x02},	// 46
 151              {0x03,0x02},	// 47
 152              {0x00,0x00},	// 48
 153          
 154              {0x00,0x40},	// 49
 155              {0x01,0x40},	// 50
 156              {0x02,0x40},	// 51
 157              {0x03,0x40},	// 52
 158          	{0x05,0x04},	// 53
 159              {0x04,0x04},	// 54
 160              {0x03,0x04},	// 55
 161              {0x00,0x00},	// 56
 162          
 163              {0x00,0x80},	// 57
 164              {0x01,0x80},	// 58
 165              {0x02,0x80},	// 59
 166              {0x03,0x80},	// 60
 167              {0x05,0x08},	// 61
 168              {0x04,0x08},	// 62
 169          	{0x03,0x08},	// 63
 170              {0x00,0x00}		// 64
 171          };
 172          
 173          /* 64-bit key convert to 56-bit key with compressed-convert */
 174          extern void Key64_To_56(unsigned char Key_64[],unsigned char Key_56[]) {
 175   1          unsigned char i,j,deal_data;
 176   1      	unsigned char index=0;
 177   1      	unsigned char NewKey_index,NewKey_data;
 178   1      
 179   1      	for (i=0;i<7;i++)
C51 COMPILER V6.12  DES                                                                    01/17/2003 18:27:26 PAGE 4   

 180   1          	Key_56[i]=0;
 181   1      	for (i=0;i<8;i++) {
 182   2          	deal_data=Key_64[i];
 183   2              for (j=0;j<7;j++) {		// only cycle 7 times is enough
 184   3      			if ((deal_data & 0x80)==0x80) {
 185   4          			NewKey_index=Key_64_To_56_Tab[index][0];
 186   4                      NewKey_data=Key_64_To_56_Tab[index][1];
 187   4      				Key_56[NewKey_index] |= NewKey_data;
 188   4                  }
 189   3      			index++;
 190   3                  deal_data <<= 1;
 191   3              }
 192   2              index++;
 193   2          }
 194   1      }
 195          /*
 196           * 将56bits的key共7个字节分成左右两半各28 bits,然后分别循环"cyc_times"次,
 197           * 循环方向由"di"值确定:
 198           * 若di=0, 向左循环,用于加密
 199           *   di=1, 向右循环,用于解密
 200           */
 201          void KeyRotate(unsigned char Key_56[],unsigned char cyc_times,unsigned char di) {
 202   1      	unsigned char temp1,temp2;
 203   1      	char i,j;
 204   1      
 205   1          for (i=0;i<cyc_times;i++) {
 206   2              if (di==0) {		/* 向左循环 1 bit */
 207   3      			temp1=0;
 208   3      			for (j=6;j>=0;j--) {
 209   4          	    	temp2=Key_56[j];
 210   4      				Key_56[j]<<=1;
 211   4      				Key_56[j] |= ((temp1>>7) & 0x01);
 212   4      				temp1=temp2;
 213   4              	}
 214   3                  /* Key_56[6].0 must be 0, so not to add "Key[6] &= 0xfe" */
 215   3                  Key_56[6] |= ( (Key_56[3]>>4) & 0x01);
 216   3      			Key_56[3] &= 0xef;
 217   3                  Key_56[3] |= ( (temp2>>3) & 0x10);
 218   3              }
 219   2              else {              /* 向右循环 1 bit */
 220   3              	temp1=0;
 221   3      			for (j=0;j<7;j++) {
 222   4          	    	temp2=Key_56[j];
 223   4      				Key_56[j]>>=1;
 224   4      				Key_56[j] |= ((temp1<<7) & 0x80);
 225   4      				temp1=temp2;
 226   4              	}
 227   3                  /* Key_56[0].7 must be 0, so not to add "Key[6] &= 0xfe"  */
 228   3                  Key_56[0] |= ( (Key_56[3]<<4) & 0x80);
 229   3      			Key_56[3] &= 0xf7;
 230   3                  Key_56[3] |= ( (temp2<<3) & 0x08);
 231   3              }
 232   2          }
 233   1      }
 234          /*
 235           * 0(行)   14,17,11,24, 1, 5, 3,28,
 236           * 1       15, 6,21,10,23,19,12, 4,
 237           * 2       26, 8,16, 7,27,20,13, 2,
 238           * 3	   41,52,31,37,47,55,30,40,
 239           * 4       51,45,33,48,44,49,39,56,
 240           * 5       34,53,46,42,50,36,29,32
 241           */
C51 COMPILER V6.12  DES                                                                    01/17/2003 18:27:26 PAGE 5   

 242          static unsigned char Key_56_To_48_Tab[56][2]={
 243          	{0x00,0x08},	/* 1 */
 244              {0x02,0x01},	/* 2 */
 245              {0x00,0x02},	/* 3 */
 246              {0x01,0x01},	/* 4 */
 247              {0x00,0x04},	/* 5 */
 248              {0x01,0x40},	/* 6 */
 249              {0x02,0x10},	/* 7 */
 250              {0x02,0x40},	/* 8 */
 251          
 252              {0x00,0x00},
 253              {0x01,0x10},	/* 10 */
 254              {0x00,0x20},	/* 11 */
 255              {0x01,0x02},	/* 12 */
 256              {0x02,0x02},	/* 13 */
 257              {0x00,0x80},	/* 14 */
 258              {0x01,0x80},	/* 15 */
 259              {0x02,0x20},	/* 16 */
 260          
 261              {0x00,0x40},	/* 17 */
 262              {0x00,0x00},
 263              {0x01,0x04},	/* 19 */
 264              {0x02,0x04},	/* 20 */
 265              {0x01,0x20},	/* 21 */
 266              {0x00,0x00},
 267              {0x01,0x08},	/* 23 */
 268              {0x00,0x10},	/* 24 */
 269          
 270              {0x00,0x00},
 271              {0x02,0x80},	/* 26 */
 272              {0x02,0x08},	/* 27 */
 273              {0x00,0x01},	/* 28 */
 274              {0x05,0x02},	/* 29 */
 275              {0x03,0x02},	/* 30 */
 276              {0x03,0x20},	/* 31 */
 277              {0x05,0x01},	/* 32 */
 278          
 279              {0x04,0x20},	/* 33 */
 280              {0x05,0x80},	/* 34 */
 281              {0x00,0x00},
 282              {0x05,0x04},	/* 36 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -