Question

In: Computer Science

UNIX ONLY -- DIFFICULT LAB ASSIGNMENT This is an extremely difficult subject for me. Could you...

UNIX ONLY -- DIFFICULT LAB ASSIGNMENT

This is an extremely difficult subject for me. Could you please give step by step instructions on how to write a script called "encrypt_password.sh" and say line by line what the code should be to complete the assignment according to the instructions and examples below?

The assignment will be done entirely in Terminal on Mac

Our Lab assignment is as follows:

In this lab, you will write a script called encrypt_password.sh to encrypt passwords. The script will ask user to enter user name and password repeatedly and will store it in file unencrypted. Then the script will read the user names and the corresponding passwords from the unencrypted file one line at a time, encrypt the password, and store the name and the encrypted password in another file. The objective of this lab is to familiarize and gain proficiency with the following:

• Use of loops (while and for)

• Read input from keyboard

• Read from file line by line

• Use of md5sum utility to generate md5 hash

The md5sum utility (command) computes and checks a MD5 message digest of a file. Message digest is the cryptographic hash of a clear text. Cryptographic hash or message digest is a one-way encryption; once encrypted the hash cannot be decrypted to get the original text. There are many algorithms for generating message digest or hash from text. MD5 is one such algorithm. Other algorithms are SHA256, SHA512etc. Unix/Linux has utilities(commands) to generate message digest using these algorithms. MD5 uses 128-bit encryption and is considered not secured. SHA 256 or SHA 512 is more secured than MD5. Following is the command to create a hash of a file called “input.txt” using MD5algorithm is

md5sum input.txt

The command to create a hash of the string “CSC2500 is fun and interesting” is

echo CSC2500 is fun and interesting | md5sum

Your script should accept two command line arguments. The 1st argument should be number of users and the 2nd argument should be the name of the unencrypted file.

Your script should do the following

1. Accept user name and password using for loop repeatedly (as many times as the 1st argument).

2. Write the user name and password to the designated file (2nd argument) separated by colon (:) as it reads the inputs from user.

3. Once all the names and passwords are written into the file; read the unencrypted name and password one line at a time from the unencrypted file and encrypt the password and write the username and the encrypted password into the encrypted file (separated by colon). The name of the encrypted file should be same as the unencrypted file with an extension .enc. For example, if the name of the unencrypted file is “user”, the name of the encrypted file should be “user.enc”

Following is an example of the execution of the script

./encrypt_password.sh 3 userInfo

Enter Name: user23

Enter Password: lol

Enter Name: user21

Enter Password: hehe

Enter Name: Mike

Enter Password: password

After the successful execution of the script the current directory should contain two files name userInfo and userInfo.enc

The content of userInfo should be

user23:lol

user21:hehe

Mike:password

The content of the userInfo.enc should be

user23:59bcc3ad6775562f845953cf01624225

user21:f68277605308bf967037423eb4f03fcf

Mike:11408e6f3846af9379b7ca60cbf1b913

Following is an example script that reads lines from a file called input.txt and will print 1st and 3rd words of all the lines.

#!/bin/bash

while read -r line #line is a variable which will store the line read from the file

do

first=$(echo $line | cut -d ' ' -f 1)

third=`echo $line | cut -d ' ' -f 3`

echo $first $third done

THANKS!

Solutions

Expert Solution

You could try the below script

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

#Accepting the user name and password for 'n' no. of users
#!/bin/bash
#Here $2 refers to the second command line arguement
#Unencrypter file name
UNEC_FILE="$2"
#Here $1 refers to the first command line arguement
for ((i=1; i<="$1"; i++))
do
echo "Enter username:"
read username
echo "Enter password:"
read password
echo "$username":"$password" >> "$UNEC_FILE"
done

#Reading the unencrypted file
while IFS= read -r line
do
IFS=':' read -r username password <<< "$line"
hash=`echo "$password" | md5sum`
echo "$username":"$hash" >> "$UNEC_FILE.enc"
done < "$UNEC_FILE"

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

Save this by an arbitary name like 'test.sh', execute it by calling 'sh test.sh <arg-1> <arg-2>'. For eg, if the no.of users is 3 and the name of the unencrypted file is 'file', we could call this by executing 'sh test.sh 3 file'


Related Solutions

PLEASE ANSWER ONLY IF YOU KNOW subject is Unix System programming Create a SQLite Replit(or SQLite...
PLEASE ANSWER ONLY IF YOU KNOW subject is Unix System programming Create a SQLite Replit(or SQLite on another coding platform) that creates a table representing students in a class, including   name, graduation year, major, and GPA. Include two queries searching this student data in different ways, for example searching for all students with graduation year of 2021, or all students with GPA above a certain number.
Pricing is extremely difficult for companies to get right. Not only does price provide revenue and...
Pricing is extremely difficult for companies to get right. Not only does price provide revenue and enable a company to maximize profit, price also reflects the value of the product or service. Some examples of pricing strategies are: Premium Pricing: a high price for a product (e.g. Lexus or Ferrari) Penetration Pricing: a low price to win market position (e.g. Walmart entering a new market) Economy Pricing: a no-frills low price (e.g. Low-cost carriers) Bundle Pricing: a combination package of...
Hi, please could someone be of assistance with this assignment for me. Thank you The objective...
Hi, please could someone be of assistance with this assignment for me. Thank you The objective of this assignment is to practice the use of control objects in GUI design. You are required to create a 4- function calculator. See pic below. Calculator.png The calculator should have buttons for all 10 numbers, the decimal point, the four operations (+,-,/,*), an equal “=” button, a "main display" (TextBox or RichTextBot), a backspace button and a clear “C” button. When you create...
The following are questions for discussion assignment. Could you please assist me with these questions? Thank...
The following are questions for discussion assignment. Could you please assist me with these questions? Thank you. Rite Aid Corporation; NYSE: RAD Income Statement: Listed as Consolidated of Operations, page 76 Balance Sheet: Listed as Consolidated Balance Sheets, page 75 Statement of Stockholder's Equity: Listed as Consolidated Statements of Stockholders' Equity, page 78 Statement of Cash Flows: Listed as Consolidated Statements of Cash Flows, page 79 https://www.sec.gov/Archives/edgar/data/84129/000104746918003207/a2235393z10-k.htm SEC 10K Project: Income Statement Respond to one or more question(s) from each...
If a company’s budget were extremely limited and could only afford to offer one benefit, which...
If a company’s budget were extremely limited and could only afford to offer one benefit, which would you select? Provide your rationale for your answer.
can you please give me short answers only 4 or 5 sentence and please could you...
can you please give me short answers only 4 or 5 sentence and please could you tpye the answers i do not want handwriting,,, You are creating a model for a manufacturing company with four major plants and ten warehouses. They want to reduce costs by determining the optimal number and location of the plants and warehouses. During the initial set of meetings, one of the team members is very concerned about modeling the “samples” that the firm sends out....
System Administration Linux/Unix This lab is for you to research and implement old school DNS for...
System Administration Linux/Unix This lab is for you to research and implement old school DNS for your virtualized environment Currently, if you tried to ping your server01 by IP address (192.168.10.11), you would receive a response. If you tried to ping using its hostname "server01", it would result in "ping: hostname: Temporary failure in name resolution" 1) Research how and where to implement 2) Create the following entries: 192.168.10.1 router 192.168.10.11 SRV1 192.168.10.12 SRV2 192.168.10.13 client 3) Ensure these hostnames...
Could someone assist me in setting up an annotated outline for the below listed assignment? For...
Could someone assist me in setting up an annotated outline for the below listed assignment? For this task, you will prepare an annotated outline comparing the different types of sampling techniques that you read about in the Jackson and Trochim et al. readings for this week. Headings for the outline should be divided between probability and nonprobability sampling. Each sampling technique should be described, including when it is best to use the particular method, identify the question type for the...
Tell me about about a time you had to deal with a difficult patient
Tell me about about a time you had to deal with a difficult patient
how do you feel about Chi-square testing is it most a difficult subject?
how do you feel about Chi-square testing is it most a difficult subject?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT