Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

unspecified issues as you can a data into the and give 21.2 DES: data write. In

ID: 3807045 • Letter: U

Question

unspecified issues as you can a data into the and give 21.2 DES: data write. In the DES block, we included inputs for writing cipher block storage, but did not include that logic in the partitioned diagram (Figure 2 Update the block diagram to include the ability to read in data. Specify how this works 21.3 DEs: interrupt. In the DES specification and block diagram, add an put interrupt that stops DES computation. Be sure to specify the values of the outputs on interrupt, the does the system goes into, and what happens during the interruption of data input. How execution resume? 21.4 DES: Plaintext output. At the end of cracking, we would like to output the plaintext data. Specify this feature and include it in the partitioned block diagram.

Explanation / Answer

I'm presuming that you need a program to encrypt and decrypt a file using the DES system of crytography. I am writing the below program to demonstrate the same.

Java program ---

----------------------------------------------------------------------------------------------------------------------------------------------

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.security.InvalidAlgorithmParameterException;

import java.security.InvalidKeyException;

import java.security.NoSuchAlgorithmException;

import java.security.spec.AlgorithmParameterSpec;

import javax.crypto.Cipher;

import javax.crypto.CipherInputStream;

import javax.crypto.CipherOutputStream;

import javax.crypto.KeyGenerator;

import javax.crypto.NoSuchPaddingException;

import javax.crypto.SecretKey;

import javax.crypto.spec.IvParameterSpec;

public class DESEncryptionExample {

    private static Cipher encryptCipher;

    private static Cipher decryptCipher;

    private static final byte[] iv = {11, 22, 33, 44, 99, 88, 77, 66};

    public static void main(String[] args) {

        String clearTextFile = "/Users/pankaj/source.txt";

        String cipherTextFile = "/Users/pankaj/cipher.txt";

        String clearTextNewFile = "/Users/pankaj/source-new.txt";

        try {

            //create SecretKey using KeyGenerator

            SecretKey key = KeyGenerator.getInstance("DES").generateKey();

            AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);

             

            //get Cipher instance and initiate in encrypt mode

            encryptCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");

            encryptCipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);

             

            //get Cipher instance and initiate in decrypt mode

            decryptCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");

            decryptCipher.init(Cipher.DECRYPT_MODE, key, paramSpec);

             

            //method to encrypt clear text file to encrypted file

            encrypt(new FileInputStream(clearTextFile), new FileOutputStream(cipherTextFile));

             

            //method to decrypt encrypted file to clear text file

            decrypt(new FileInputStream(cipherTextFile), new FileOutputStream(clearTextNewFile));

            System.out.println("DONE");

        } catch (NoSuchAlgorithmException |

                 NoSuchPaddingException |

                 InvalidKeyException |

                 InvalidAlgorithmParameterException |

                 IOException e) {

            e.printStackTrace();

        }

    }

    private static void encrypt(InputStream is, OutputStream os) throws IOException {

         

        //create CipherOutputStream to encrypt the data using encryptCipher

        os = new CipherOutputStream(os, encryptCipher);

        writeData(is, os);

    }

    private static void decrypt(InputStream is, OutputStream os) throws IOException {

         

        //create CipherOutputStream to decrypt the data using decryptCipher

        is = new CipherInputStream(is, decryptCipher);

        writeData(is, os);

    }

     

    //utility method to read data from input stream and write to output stream

    private static void writeData(InputStream is, OutputStream os) throws IOException{

        byte[] buf = new byte[1024];

        int numRead = 0;

        //read and write operation

        while ((numRead = is.read(buf)) >= 0) {

            os.write(buf, 0, numRead);

        }

        os.close();

        is.close();

    }

}

------------------------------------------------------------------------------------------------------------------------------------

Expected Output --

According to the question image that you have put up, the expected output of this program should be as:

Both the plain text files will have the same data, while the encrypted files don't have the plain text data.

This essentially explains you the DES standard of cryptography.