0% found this document useful (0 votes)
37 views

ACNS LAB 2 - Data Encryption Standard

The document discusses the Data Encryption Standard (DES) algorithm. It provides details on: - DES is a symmetric-key block cipher with a 64-bit block size and 56-bit effective key size published by NIST. - It uses a Feistel network with 16 rounds. The round function applies a 48-bit round key to the expanded 32-bit right input using substitution boxes and permutations. - The key schedule generates 16 48-bit round keys from the 56-bit input key using permutations, drops, and compression.

Uploaded by

AbdissaTadese
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

ACNS LAB 2 - Data Encryption Standard

The document discusses the Data Encryption Standard (DES) algorithm. It provides details on: - DES is a symmetric-key block cipher with a 64-bit block size and 56-bit effective key size published by NIST. - It uses a Feistel network with 16 rounds. The round function applies a 48-bit round key to the expanded 32-bit right input using substitution boxes and permutations. - The key schedule generates 16 48-bit round keys from the 56-bit input key using permutations, drops, and compression.

Uploaded by

AbdissaTadese
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Experiment No.

3: The Data Encryption Standard (DES)

The Data Encryption Standard (DES) is a symmetric-key block cipher published by the National
Institute of Standards and Technology (NIST).

DES is an implementation of a Feistel Cipher. It uses 16 round Feistel structure. The block size
is 64-bit. Though, key length is 64-bit, DES has an effective key length of 56 bits, since 8 of the
64 bits of the key are not used by the encryption algorithm (function as check bits only). General
Structure of DES is depicted in the following illustration −

Since DES is based on the Feistel Cipher, all that is required to specify DES is −

 Round function
 Key schedule
 Any additional processing − Initial and final permutation

Initial and Final Permutation


The initial and final permutations are straight Permutation boxes (P-boxes) that are inverses of
each other. They have no cryptography significance in DES. The initial and final permutations
are shown as follows −

Round Function
The heart of this cipher is the DES function, f. The DES function applies a 48-bit key to the
rightmost 32 bits to produce a 32-bit output.
 Expansion Permutation Box − Since right input is 32-bit and round key is a 48-bit, we
first need to expand right input to 48 bits. Permutation logic is graphically depicted in the
following illustration −

 The graphically depicted permutation logic is generally described as table in DES


specification illustrated as shown −
 XOR (Whitener). − After the expansion permutation, DES does XOR operation on the
expanded right section and the round key. The round key is used only in this operation.
 Substitution Boxes. − The S-boxes carry out the real mixing (confusion). DES uses 8 S-
boxes, each with a 6-bit input and a 4-bit output. Refer the following illustration −

 The S-box rule is illustrated below −


 There are a total of eight S-box tables. The output of all eight s-boxes is then combined in
to 32 bit section.
 Straight Permutation − The 32 bit output of S-boxes is then subjected to the straight
permutation with rule shown in the following illustration:

Key Generation
The round-key generator creates sixteen 48-bit keys out of a 56-bit cipher key. The process of
key generation is depicted in the following illustration −
The logic for Parity drop, shifting, and Compression P-box is given in the DES description.

DES Analysis
The DES satisfies both the desired properties of block cipher. These two properties make cipher
very strong.

 Avalanche effect − A small change in plaintext results in the very great change in the
ciphertext.
 Completeness − Each bit of ciphertext depends on many bits of plaintext.

During the last few years, cryptanalysis have found some weaknesses in DES when key selected
are weak keys. These keys shall be avoided.

DES has proved to be a very well designed block cipher. There have been no significant
cryptanalytic attacks on DES other than exhaustive key search.
Encrypt an object with DES : DES Data
Encryption Standard « Security « Java
Tutorial
import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SealedObject;
import javax.crypto.SecretKey;

public class Main {


private static void writeToFile(String filename, Object object) throws
Exception {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new
File(filename)));
oos.writeObject(object);
oos.flush();
oos.close();
}

public static void main(String[] args) throws Exception {


SecretKey key = KeyGenerator.getInstance("DES").generateKey();
writeToFile("secretkey.dat", key);
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, key);
SealedObject sealedObject = new SealedObject("THIS IS A SECRET MESSAGE!",
cipher);
writeToFile("sealed.dat", sealedObject);
}
}

Decrypt an object with DES : DES Data Encryption


Standard « Security « Java Tutorial
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;

import javax.crypto.Cipher;
import javax.crypto.SealedObject;
import javax.crypto.SecretKey;

public class Main {


private static Object readFromFile(String filename) throws Exception {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new
File(filename)));
Object object = ois.readObject();
ois.close();
return object;
}

public static void main(String[] args) throws Exception {


SecretKey key = (SecretKey) readFromFile("secretkey.dat");
SealedObject sealedObject = (SealedObject) readFromFile("sealed.dat");
String algorithmName = sealedObject.getAlgorithm();
Cipher cipher = Cipher.getInstance(algorithmName);
cipher.init(Cipher.DECRYPT_MODE, key);
String text = (String) sealedObject.getObject(cipher);
System.out.println("Text = " + text);
}
}

Encryption and Decryption using DES

Description

DES.java generates the sysmetric key using DES algorithm. Key size assigned here is 64 bits. It
works only for the key size of 64 bits. 56 bits is mentioned in the coding remaining 8bits is
accessed from inbuilt package. Encryption and decryption method is written based on DES
algorithm. Message to encrypt can be given as input. Encrypted and decrypted text is displayed
in message dialog.

Filename: DES.java

import javax.swing.*;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Random ;
class DES {
byte[] skey = new byte[1000];
String skeyString;
static byte[] raw;
String inputMessage,encryptedData,decryptedMessage;

public DES() {
try {
generateSymmetricKey();

inputMessage=JOptionPane.showInputDialog(null,"Enter message to encrypt");


byte[] ibyte = inputMessage.getBytes();
byte[] ebyte=encrypt(raw, ibyte);
String encryptedData = new String(ebyte);
System.out.println("Encrypted message "+encryptedData);
JOptionPane.showMessageDialog(null,"Encrypted Data "+"\n"+encryptedData);

byte[] dbyte= decrypt(raw,ebyte);


String decryptedMessage = new String(dbyte);
System.out.println("Decrypted message "+decryptedMessage);

JOptionPane.showMessageDialog(null,"Decrypted Data "+"\n"+decryptedMessage);


}
catch(Exception e) {
System.out.println(e);
}

}
void generateSymmetricKey() {
try {
Random r = new Random();
int num = r.nextInt(10000);
String knum = String.valueOf(num);
byte[] knumb = knum.getBytes();
skey=getRawKey(knumb);
skeyString = new String(skey);
System.out.println("DES Symmetric key = "+skeyString);
}
catch(Exception e) {
System.out.println(e);
}
}
private static byte[] getRawKey(byte[] seed) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("DES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
kgen.init(56, sr);
SecretKey skey = kgen.generateKey();
raw = skey.getEncoded();
return raw;
}
private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "DES");
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "DES");
Cipher cipher = Cipher.getInstance("DES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
public static void main(String args[]) {
DES des = new DES();
}
}

You might also like