日期:2013-12-25  浏览次数:20417 次

如何实现 DES 算法(全)。

这是摘自清华BBS的一篇文章,洋文的,小弟把它翻成中文请各位高手指点。
分号(;)后的话是小弟的翻译,井号(#)后的是小弟的一点感想。


                          How to implement the
                     Data Encryption Standard (DES)

                        A step by step tutorial
                              Version 1.2


The Data Encryption Standard (DES) algorithm, adopted by the U.S.  
government in 1977, is a block cipher that transforms 64-bit data blocks  
under a 56-bit secret key, by means of permutation and substitution. It  
is officially described in FIPS PUB 46. The DES algorithm is used for  
many applications within the government and in the private sector.

This is a tutorial designed to be clear and compact, and to provide a
newcomer to the DES with all the necessary information to implement it
himself, without having to track down printed works or wade through C  
source code. I welcome any comments.
Matthew Fischer <mfischer@heinous.isca.uiowa.edu>

;上面是介绍,我就不翻了。 ;)


Here's how to do it, step by step:

1  Process the key.
;生成密钥

1.1  Get a 64-bit key from the user. (Every 8th bit is considered a  
parity bit. For a key to have correct parity, each byte should contain  
an odd number of "1" bits.)
;从用户处得到一个64位的密钥。(每8位一组,每组的第8位是校验位。如果校验
正确,每个字节应该有一个为1的

1.2  Calculate the key schedule.
;计算密钥表

1.2.1  Perform the following permutation on the 64-bit key. (The parity  
bits are discarded, reducing the key to 56 bits. Bit 1 of the permuted  
block is bit 57 of the original key, bit 2 is bit 49, and so on with bit  
56 being bit 4 of the original key.)
;对64位的密钥进行如下的置换。(去掉校验位,密钥的实际长度是56位。置换后的
;第一位是原密钥的第57位,第二位是原第49位,第五十六位就是原来密钥的第4位。)
# 古怪的置换,哪位大哥能写出算式?
# 好象是分成两部
#       for(j=57;j<64;j++)
#       {
#               for(i=j;i<0;i-=8)
#               {
#                       if(k=28)
#                               break;
#                       c[k]=i;
#                       k++;
#               }
# 这是前28位,不知道对不对?请指正。


                        Permuted Choice 1 (PC-1)

                        &n