The DES encryption algorithm applies the implementation of the DES encryption algorithm for MCS51 single-chip assembly language in the access control system: This article describes the method of writing a DES encryption algorithm in the access control system. Briefly describe the principle of the DES encryption algorithm, and implement the subroutine. Keywords: Access control system DES encryption algorithm MCS51 single-chip assembly language access control system due to its confidentiality, the encryption of information in the access control system is very important. The structure of the access control system we have developed is shown in the figure: the access control system is located in a building, from the calculation center server, a controller (including keyboard, card reader,) at the computing center server, in each layer The actuator is composed, the server and the industrial control of each layer are transmitted with a 20mA current loop. Each layer of industrial control is transmitted with RS485 standard twisted pair and up to 32 controllers. The central processor of the controller uses MCS89C51. In order to prevent data transmission, some people may hook the monitor device in the RS485 bus, steal the IC card password. Therefore, the password contains the DES encryption algorithm during transmission, and the industrial control machine uses the C language in the DOS environment. The program can be found on the Internet, the DES encryption algorithm of the controller MCS51 single-chip in this article. The encryption algorithm of the DES encryption algorithm can be expressed as follows: DES (m) = IP-1 · T16 · T15 · T14 · ... · T2 · T1 · IP program mainly completes (1) IP replacement and IP reverse replacement IP-1 (2 ) The iterative process (3) of the sub-key. The data packet format of the system communication is as follows: 4 byte synchronization head 1 bytes (command word) 7 bytes (password) 1 calibration words According to the communication protocol: need to turn the command word and password a total of 8 Bytes are encrypted program memory allocation: the internal RAM of 8031 is distinguished as follows: 20H-27H storage changing power matrix bit address range 00-3FH (0-63) 28H-2FH storage change source Tast matrix bit address range 40-7FH ( 64-127) 30 H-37H matrix 38 H-3FH storage of temporary data is stored in the matrix of temporary data. The external RAM storage data is stored as follows: 0000H-0007H Storage command word, password 0008H-000FH storage Key 1, IP replacement and IP replacement IP-1 IP replacement has two methods implementations: 1) First, the 16 bytes of the MCS51 single-chip microcomputer, each of which has bit addresses. The source matrix is admitted to the 20H-27H (bit address space 00h-3FH), using the MOV C, Bit Mov bit, and C instruction to take the bit information to the destination matrix 28h-2Fh (bit address space 40H-7FH) can IP replacement 58 50 42 34 44 36 28 20 12 4 62 54 46 38 30 22 14 6 64 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 15 7: First replacement MOV C, 39h MOV 40H, C Note: The bit address space starts from 0 from 0, so the 39h hexadecimal number corresponds to the decimal Number of 57 IP-1 Replacement 40 8 48 16 56 24 64 32 39 7 47 15 55 23 63 31 38 6 46 14 54 6 53 21 61 29 36 4 44 12 52 20 60 28 35 3 43 Similar to the IP-1 replacement.
The advantage of this method is that the structure is simple, and the speed is faster but more occupied by the ROM space. 2) The second method is to use the method of the table; the program puts the source matrix at 30H-37H, the destination matrix is placed on 38h-3FH. Check the table Get IP replacement, IP-1 replacement number n, carry the carry mark C The right 30H-37H unit N times, the bit information is incorporated into the destination matrix. The following subprograms are used as an example of IP. MOV R7, 1; R7 sequence number iPLOOP1: MOV A, R7 MOV R6, A iPloop2: RLC 3FH; Left-rotated Matrix (R7) RLC 3EH RLC 3DH RLC 3CH RLC 3BH RLC 3AH RLC 39h RLC 38h DJNZ R6 , IPLOOP2; (R7) bit information MOV DPTR, TABLEIP MOV A, R7 MOVC A, @ DPTR A MOV R6, A MOV R5, A iPLOOP3: RLC 37H; Left Source Matrix RLC 36H RLC 35H RLC 34h RLC 33h RLC 32h RLC 31H RLC 30H MOV 00h, C; storage bit information to 0th DJNZ R6, IPLOOP3 MOV C, 00H iPloop4: RRC 30H; RRC 34H RRC 33H RRC 32H RRC 33H RRC 34H RRC 35H RRC 36H RRC 37H DJNZ R5, IPLOOP4 MOV A, R7 MOV R5, A MOV C, 00H; Taste Action Information iPloop5: RRC 38H; Right-rotated Matrix RRC 39H RRC 3AH RRC 3BH RRC 3CH RRC 3DH RRC 3EH RRC 3FH DJNZ R5, IPLOOP5 INC R7 CJNE R7, # 64, IPLOOP1 RET TABLEIP: DB 58, 50, 42, 34, 26, 18, 10, 2 DB 56, 52, 44, 36, 28, 20, 12, 4 DB 62, 54, 46, 38, 30, 22, 14, 6 dB 64, 56, 48, 40, 32, 24, 16, 8 DB 57, 49, 41, 33, 25, 17, 9, 1 DB 59, 51, 43, 35, 27, 19, 11, 3 DB 61, 53, 45, 37, 29, 21, 13, 5 DB 63, 55, 47, 39, 31, 23, 15, 7 III, DES are iterative process DES The iterative process is shown in the figure: the iterative process is divided into the following steps: (1) E Replacement 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 23 24 25 24 25 26 27 28 29 28 29 30 31 32 1 After the IP is replaced, the left 4 bytes are placed on a 30H-33H unit (L0), and the right 4 bytes are placed at a 20H-23H unit (R0). (2) E-replacement for R0, the E replacement program can refer to IP replacement, IP-1 replacement. Store the result in 8 bytes of 28H-2FH units, only 6 bits per byte are valid. B1B2B3B4B5B6. (3) The resulting result of the E replacement and K1 is different. The production of Ki is discussed below. (4) Use a subroutine to adjust the sequence of 8 bits of 28H-2FH units as follows: B1 B6 0 0 B2 B3 B4 B5 The first 2 bits are the S box line B1B6, and the last 4 bits are the S-box column B2B3B4B5. Cut S1S2 ... S8 into a large table.