Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#!/bin/bash if [ $# -eq 0 ] then echo Three args required - need an infile, outfile, thirdfile exit 1 fi ts=$(date +%s%N) openssl enc

#!/bin/bash

if [ $# -eq 0 ] then echo "Three args required - need an infile, outfile, thirdfile"

exit 1

fi

ts=$(date +%s%N)

openssl enc -e -des-cbc -salt -in $1 -out $2 -k nighthawks

te=$(date +%s%N) tt=$(( (te - ts)/1000000 ))

echo "It took $tt milliseconds to encode with DES-CBC."

This script checks for three command-line arguments. If not present, the script ends. Otherwise, the script encrypts a file specified by the first argument using the password nighthawks and des-cbc encryption. It also times the encryption by getting the system time before and after the encryption, then echoes the result.

Save the file as testdes.sh in your user (home) folder. In the terminal, change directories into your user folder, then make the above script executable using the chmod command:

# cd ~

# chmod +x testdes.sh

Now create a simple file and test the shell script:

# echo "Welcome to CSCI 3250 Computer Security" > plaintext.txt

# ./testdes.sh plaintext.txt ciphertext_des.dat decoded_des.txt

Re-run the command three times to get a more accurate picture of the amount of time the algorithm requires.

Modify the shell script (by adding a copy-paste of the last five lines of the script above) to DECODE the file in the second command-line argument ($2) and output it to a filename given by the third command-line argument ($3). Echo out the time it took to DECODE the file.

Test your script again with

# ./testdes.sh plaintext.txt ciphertext_des.dat decoded_des.txt

Use the more or cat command to display the decoded.txt file to make sure it is correctly decoded, and note the time required for encoding and decoding your message. Examine the ciphertext_des.dat file with hd.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started