How to implement DES algorithm

Source: Internet
Author: User
The DES (data encryption Standard) algorithm, which was formally licensed by the United States Government in 1977, is a method of encrypting 64-bit data with a 56-bit key. Des algorithms are applied to many situations where security encryption is required. (for example, the UNIX cipher algorithm is based on the DES algorithm). Here is a description of how to implement the DES algorithm, if you want its source code, you can go to the http//assassin.yeah.net download, the latter you have any questions you can write to me (Assassin@ynmail.com). 1-1, transform the key to obtain 64-bit key, each 8th bit as parity bit.  1-2. Transform the key. 1-2-1, discard the parity bit in the 64-bit key, according to the following table (PC-1) for key transformation to obtain a 56-bit key, in the transformation, parity bit is discarded. permuted Choice 1 (PC-1) 57 49 41 33 25 17 91 58 50 42 34 26 1810 2 59 51 43 35 2719 11 3 60 52 44 3663 55 47 39 31 23 62 54 46 38 30 2214 6 61 53 45 37 2921 13 5 28 20 12 41-2-2, the converted key is divided into two parts, the beginning 28 bits are called c[0], and the last 28 bits are called d[0]. 1-2-3, generate 16 sub keys, initial i=1. 1-2-3-1, C[i], d[i] Move left 1-bit or 2-bit, depending on the I value to determine the number of left-shifted digits. See table below i:1 2 3 4 5 6 7 8 9 10 11 12 13 14 + 15 left Shift: 16 1 1 2 2 2 2 2 2 1 2 2 2 2 11-2-3-2, c[i]d[i] as a whole to the following table (PC-2) transform, get 2 bit K[i] permuted Choice 2 (PC-2) 14 17 11 24 1 53 28 15 6 21 1023 19 12 4 26 816 7 27 20 13 241 52 31 37 47 5530 40-51 45 33 844 49 39 56 34 5346 42 50 36 29 321-2-3-3 from 1-2 to 3-1, until K[16] is computed. 2, processing 64 bits of data 2-1, get 64 bits of data, if the data length is less than 64, should be extended to 64 bits (such as 0) 2-2, the 64-bit data to the table transformation (IP) Initial PeRmutation (IP) 58 50 42 34 26 18 10 260 52 44 36 28 20 12 462 54 46 38 30 22-14 664 56 48 40 32 24 16 857 49 41 33 25 17 159 51 43 35 27 19 11 361 53 45 37 29 21 13 563 55 47 39 31 23 15, the transformed data is divided into two parts, the first 72-3 bits are called l[0], and the last 32 bits are called r[0]. 2-4. Encrypt data with 16 sub keys, initial i=1. 2-4-1, the 32-bit r[i-1] is expanded to 48-bit e[i-1]expansion (e) 32 1 2 3 4 54 5 6 7 8 98 9 10 11 12 1312 13 14 15 A 16 1716 17 18 19 0 21 22 23 24 2524 25 26 27 28 2928 29 30 31 32 12-4-2, XOR/e[i-1] and k[i], that is, E[i-1] XOR k[i]2-4-3, the result is divided into 8 6-bit long parts, the 1th to 6th bit is called b[1 , the 7th bit to the 12th bit is called b[2], and so on, the 43rd bit to 48th bit is called b[8]. 2-4-4, according to S table transform all B[j], initial j=1. All values in the S table are treated as 4-bit lengths. 2-4-4-1, the 1th and 6th digits of b[j] are combined into a 2-bit length variable m,m as the line number in S[j. 2-4-4-2, combining the 2nd and 5th digits of B[j] as a 4-bit length variable n,n as the column number in S[j. 2-4-4-3, using s[j][m][n] to replace B[J]. Substitution Box 1 (s[1]) 14 4 13 1 2 15 11 8 3 10 6 12 5 9 0 70 15 7 4 14 2 13 1 10 6 12 11 9 5 3 84 1 14 8 13 6 A 2 9 7 3 5 015 8 2 4 9 1 7 5 3 0 13s[2]15 6 1 8 14 6 11 3 4 9 7 2 13 12 0 5 103 13 4 A 9 11 50 14 7 11 10 4 13 1 5 8 12 6 9 3 2 1513 8 10-1 3 4 2 One 6 7 0 5 9s[3]10 0 9 14 6 3 15 5 1 13 12 7 11 4 2 813 7 0 9 3 4 6 10 2 8 5 14 12 11 15 0 1 2 A 5 0 6 9 8 7 4 3 5 2 12s[4]7 13 14 3 0 6 9 10 1 2 8 5 11 12 4 1513 8 11 5 6 15 2 1 910 6 9 0/7 1 3 5 2 8 0 6 1 8 9 4 5 14s[5]2 7 2 12 4 1 7 10 11 6 8 5 3 0 914 2 4 7 1 5 0 (3 9 8) 2 1 7 8 9 5 1411 6 3 0 8 7 (1 2) [+] 12 1 10 15 9 2 6 8 0 13 3 4 14 7 5------------------1110----15-4 2 7 12 9 5 6 5 1 7 6 0 13s[7]4 8 11 2 14 15 0 8 13 3 12 9 7 5 10 6 113 0 11 7 4 9 1 10 14 3 5 12 2--- 4 6 8 0 5 9-A 8 1 4 7 9 5 0 2 3 12s[8]13 2 8 4 6 15 11 1 10 9 3 14 5 0 12 71 15 13 8 11, 0 14 9 27 11 4 1 9 12 14 2 0 6 10 13 15 3, 5, 82 1 14 7 4 10-8,, 13 15 12-9 0 3 5 6 112-4-4-4, execute from 2-4 to 4-1 until B[8] is replaced. 2-4-4-5, b[1] to B[8] group, press the table (P) transform to get p. Permutation P16 7 20 2129 12 28 171 15 23 265 18 31 102 8 24 1432 27 3 919 13 30 622 11 4 252-4-6, XOR or P and l[i-1] results in r[i] =p XOR L[i-1]. 2-4-7, l[i]=r[i-1]2-4-8, start loop execution from 2-4-1 until k[16] is transformed. 2-4-5, combined transformed r[16]l[16] (Note: R as the starting 32-bit), the following table (IP-1) transform to get the final results. The Final permutation (ip**-1) 40 8 48 16 56 24 64 3239 7 The 47 15 55 23 63 3138 6 46 14 54 22 62 3037 5 45 13 53 21 61 2936 4 A description of the DES algorithm 12 52 20 60 2835 3 43 11 51 19 59 2734 2 42 10 50 18 58 2633 1 41 9 49 is 17 57. To force (0 Votes) Tempted (0 Votes) nonsense (0 Votes) Professional (0 Votes) The title party (0 Votes) passing (0 Votes) The original: How to implement DES algorithm return to network security home
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.