 Journal of Software Engineering and Applications, 20 12, 5, 20-22 doi:10.4236/jsea.2012.512b004 Published Online December 2012 (http://www.SciRP.org/journal/jsea) Copyright © 2012 SciRes. JSEA Discussion of New Padding Method in DES Encryption* Liu Chengxia Computer Science and Technology Dept. , Beijing Information and Technology University, Beijing, China. Email: cecilia7812@163.com Received 2012 ABSTRACT DES is a kind of block cipher and before DES encr yption the plain te xt be d ivided into the sa me-size blocks. But some-times the plain text can’t b e divided into the exactl y size. So p adding step is needed to pad the space of the block. The discussion of the block padding is the emphasis of this paper. A new padding method is given and at the last part of the paper the implementation o f DES using new padding method is given. Keywords: DES; Encryption ; Cipher; B lock 1. Introduction DES is the standard of data encryptio n, and als o a kind of block cipher. In block cipher the plain text be di-vided into same size block and use private key to encrypt the plai n text i nto cip her te xt. In bl ocki ng wh en t he le ngth o f the block is not as long as 64 bits we usually pad them with zero. Now we will introduce a new method to pad the lac ked bit s in t his pa per. This method i s not o nly pad zeros to them but also add the length of zero padded to the last 1 byte. So we can easy get what we pad in the block and can get rid of them fast. 2. New Padding Method The plain text is divided into 64 bits blocks . Perhaps there is not enough text to fill the last block. How to do with this? The traditional method is padding zero in the end of the block. But it does not distinguish between the padding zero and the original zero. And how can we known where i s the beginni ng of the filling ze ro? To solve these problems a new padding method be given. The synopsis of the ne w padding method is that a “length” part be added to the end of the block. [step1]: Divided the plain text into 8 bytes(64-bits).If the block size is less tha n 64 bits then goes to ste p2. [step2]: Pad the lacked bits with zero but leave the last 8 bits to memorize the length of padding zeros. [step3]: Encrypt the plain text with DES algorithm. [step4]: Decrypt the cipher text with DES algorithm. [step5]: Delete the padding zeros according to the length field. In the new Method there is one problem. How can we known if the last 8 bits is the length information or the original message? To solve this problem an explanation to prove the correctness of the method be given below. For the last block, firstly, we get the last 8 bits and think it as the length data. Then according to the length data we get the whole padding field. Whether the pad-ding field we got is full of zer o? T here will be two possi-ble results: result1: The field is full of zero . So the field is p add ing field. Delete it and get the real plain text. result2: The field is not full of zero. So the last 8 bits i s not the length of padding but the plain text. Preserve it and take the whole last block as plain text. Let us see some examples to explain the results. Ex 1: Part of the block is padded with zero. Condition: plain text: 01010011 11000000 01111100 00000000, zero padding field: 00000000 00000000 00000000, Length padding field: 00100000, the block is: 01010011 11000000 01111100 00000000 00000000 00000000 00000000 00100000. Processing: First, we get the last 8 bits of the block: 00100000. Then we presume the length of padding field is 32 bits. Second, we get the last 32 bits data from the block. Third, we find t he 32-8=24(got rid of the length field) bits data is zero. Forth, so the last 32 bits is padding field and we can de-lete it. Ex 2: The informati on bl ock. *Supported by Funding Project for Academic Human Resources De-velopment in Institutions of Higher Learning Under the Jurisdiction of Beijing Municipality(PHR201008428) and Project for Excellent Tal-ents of the Organization Department of Beijing Municipality (2010 D005007000003), Supported by the General program of science and technology development project of Beijing Municipal Education Com-mission under Grant No.KM201110772013. Discussion of New Padding Method in DES Encryption Copyright © 2012 SciRes. JSEA 21 Condition: plain text: 01010011 11000000 01111100 00000000 00000000 00000100 00000000 00100000, so the block is: 01010011 11000000 01111100 00000000 00000000 00000100 00000000 00100000. Processing: First, we get the last 8 bits of the block:00100000. Then we presume the length of padding field is 32 bits. Second, we get the last 32 b its d ata from the block. Thi rd, we find the 32-8 = 24(got rid of the length field) bits data is not zer o. Forth, So the las t 32 bits is inf ormation field . Ex 3: The error case. Condition: plain text: 01010011 11000000 01111100 00000000 00000000 00000000 00000000 00100000, the block is: 01010011 11000000 01111100 00000000 00000000 00000000 00000000 00100000. Processing: First, we get the last 8 bits of the block: 00100000. Then we presume the length of padding field is 32 bits. Second, we get the last 32 bits data from the block. Third, we find t he 32-8=24(got rid of the length field) bits data is zero. Forth, so the last 32 bits is padding field and we can delete it. W e get error result. If we use the new padding method to do the padding there will be some errors. But we can analyze it and we get a conclusion that it has less error than old method whic h be used in zero padding. Let us make a math proving. If: T he probability of every kind of block is 1/264. The length of padding field is ” L”. old: If the last ”L” bits are zero the original message may have11/2Lii=∑ possibilities. Then the error probabil-ity is 6464111/2 *1/2LiELiP= ==∑∑ (1) New: If the last 8 bits are zero the original message may have 2 possibilities. Then the error probability is 646411/2 *1/2LELP==∑ (2) So the new padding method is more exactly. Then the next sectio n will give t he i mple mentation o f DES a nd the new padding method is used in it. 3. Implementat ion Implementation of the DES algorithm is given below. We use the java as the programming language. The new padding method is used in it. There are an interface for DES encryptio n, a class for block processing and a class for implementation of the DES. And we will introduce the defini tion of them below. First the Figure 1 show the relation between different class or interface. T he test class is used in tes ting and we will not introduce it here. The user uses the interface IDES to do the encryption. And then the IDES can be implemented in the DES class. And then the method in DES class will call the method in block class to do de-tailed op e ration. 3.1. Inter face IDE S 1) encrypt(byte[] src,byte[] dest,DESKey key) The method is used to encrypt the plain text with the DES key and get the cipher text. 2) decrypt(byte[] src,byte[] dest,DESKey key) The method is used to decrypt the cipher text with the DES key and get the plain te xt. 3.2. Class Block 1) The private List(Bit) bits; Used to store the bits se-quence. Returns the part(from the start position to the end position) of the bloc k. Block getBlo c kPart(int start, int end) { Block newblock = new B lock(0); newblock.bits =this.bits.subList(start, e nd); return newblo ck; } 2) Set the bits with new value at the position ap-pointed. Block setValue(byte[] value, int offset, int count) { Block newblock = new B lock(0); for (int i = 0; i < co unt;i++) { Block curPart = new Block(0).setValue(8,value[i+offset]); newblock.bits.a d dAll(curP ar t. b its) ; } return newblo ck; } Figure 1. Main Frame of the Program. Discussion of New Padding Method in DES Encryption Copyright © 2012 SciRes. JSEA 22 3) Joins this and block by creating a new block with all bits of this followed by all bit s of block. Block joinBlock(Block block) { Block newblock = new B lock(0); newblock.bits.a d dAll(this.b its); newblock.bits.a d dAll(blo ck.bits); return newblo ck; } 4) Removes all bits larger than new length. Block trim(int newlength) { Block newblock = new B lock(0); newblock.bits = this.bit s. subList(0, newlength); return newblo ck; } 3.3. The Implementation of IDES The class ”DES” implements the interface ”IDES”. 1) Implement the DES encrypt ion. int encrypt(byte[] src,byte[] dest,DESKey key) { get plain block s. while(not end){ encryptPadding(plain block); for (int round=0; round<16;round++) {encryptbloc k(plain block);} } return number of blocks. } 2) The method is used to imp lement the Interface me-thod. int decrypt(byte[] src,byte[] dest,DESKey key) { get cipher blocks. while(not end){ decryptPadding(cipher block); for (int round=0; round<16;round++) {decryptblock(cipher block);} } return number of blocks. } 3) Pad the space in the block less than 64 bits. Block encryptPadding(Block block) { if (block.getLength() == 64) {re t urn bl ock; //no pa ddi ng} else if (block.getLength() == 0) {//set length=64(0x40) return new Block(0).setValue(64 ,64); } else {//padding 64-block’s length bits len=block.getLength(); pad=new Block(0).setValue(0,len,64-len) return block.joinBlock(pad); } } 4) Delete the appending bits in the block. Block decryptPadding(Block block) { int padding= block.getBlockPart(56 ,64).getValue(); if (padding > 64) { //padd ing length must less than 64 thro w ne w Runt i meExce p tio n ( "W r o ng" ) ; } return block.trim(64 - padding); } This is the main definition of the interface and the class. The detail of the implementation of the method is omitted. The test results will be given in the next sectio n. 4. Conclusion This paper is discussion of DES padding method. Al-though there are many problems in the new padding me-thod we will focus on how to modify the DES algorithm to make it more effectively and more safely in future st udy. 5. Acknowledgement s The autho rs would li ke to tha nk the co lleag ues who give much help and also thank the students who make the testing carefully. REFERENCES  Federal Information, ”DATA ENCRYPTION STAN-DARD (DES)”, . http://www.itl.nist.gov/fipspubs/fip46-2.htm  J. Orlin Grabbe, ”The DES Algorithm Illustrated”,. http://www.aci.net/kalliste/des.htm  Alfred J. Menezes, Paul C. van Oorschot, Scott A. ans-tone, ”Handbook of Applied Cryptography”,. CRC Press,1996, pp250-259  Brice Schneier, ”Applied Cryptography 2ND Edition: Protocols, Algo r ithms and Source Code in C”,. Now York: Wiley John and Sons,1996