+1 (208) 254-6996 [email protected]
Select Page

Procedure

Implement one program that has two functions: one for encryption and one for decryption.

Don't use plagiarized sources. Get Your Custom Essay on
Build A C Program That Has Two Functions: One For Encryption And One For Decryption.
Just from \$13/Page

Encryption: 1. Read keys from user input. Prompt the user to enter a character for each key. 2. Read the plain text (“data”) from the input file. The name of the input file is one of the command line argument. 3. Implement your encryption algorithm. 4. Encrypt “data” and write to a file. (The name of the file is chosen by the programmer.)

Decryption: 1. Read keys from user input. Prompt the user to enter a character for each key. 5. Read the file that encrypted data was saved and extract the encrypted “data”. The name of the encrypted file is one of the command line argument. 2. Implement your decryption algorithm. 3. Decrypt the “data” and write to a file.

Encryption – build a C program that encrypts a text file in the following manner: The internal operation of the iteration steps are shown in the figure below.

Text file

Iteration 1 Key 1 for 1st iteration

Iteration 2 Key 2 for 2nd iteration

Encrypted file

Each stage takes two inputs: 1. Data (16bits at a time, which is two characters) 2. Key (8bits, which is one character)

Steps: • Break the 16bit input to two 8bit fields (L and R). Then interchange their places. i.e. move the

left byte to right, and the right to left. • Perform XOR of L (now in right side) and K (the 8bit key for this iteration) • The 16bit output is constructed simply by putting the new left and right fields together. • If there is an odd number of bytes in the file (you have 8bits at the end of file) XOR the byte with

the key. • Iteration 1 and iteration 2 just use different keys.

Procedure Implement one program that has two functions: one for encryption and one for decryption. Encryption:

1. Read keys from user input. Prompt the user to enter a character for each key. 2. Read the plain text (“data”) from the input file. The name of the input file is one of the

command line argument. 3. Implement your encryption algorithm. 4. Encrypt “data” and write to a file. (The name of the file is chosen by the programmer.)

Decryption: 1. Read keys from user input. Prompt the user to enter a character for each key. 5. Read the file that encrypted data was saved and extract the encrypted “data”. The name of the

encrypted file is one of the command line argument. 2. Implement your decryption algorithm. 3. Decrypt the “data” and write to a file.

Your program should have two command line arguments. (We will assume that the order of command line arguments will always be the same.)

1. The first command line argument should be the E to encrypt the file or D to decrypt the file. 2. The name of either the text input file to encrypt or the name of the encrypted file to be decrypt.

The encryption function should create a text file with encrypted data. The decryption function should create a text file with the original data. The input and encrypt files will be in the same directory as the executable so there is no paths needed. Error checking:

1. The correct number of command line arguments have been entered. If not, print to the screen an output message and end the program.

2. The data file or the encrypted file exists. If not, print to the screen an output message and end the program.

3. The encrypt file or data file can be written. If not print to the screen an output message and end the program.

4. The user enters two keys when prompted (A character or a single digit separated by a space and another character or single digit. If not ask the user again, until they can enter it correctly.

Objectives of Program (What you grade is based on) I will be using Cygwin (gcc compiler) to run and test your programs. Programs should:

• Compile, no syntax errors or warnings. (5pts) • Helpful comments. (5pts) • Use command line arguments. (5pts) • Request input from user. (5pts) • Open, read and write to text files. (5pts) • Error check for the 4 error checking steps listed above. (10pts) • Encrypted and decrypted functions have prototypes. (5pts) • Correct function definitions and call to functions (This is the main portion of the program) (60pts)

Example: Suppose your data file contained the following:

the end of the semester is near. 2020 has been a very strange year. Wishing all of you a Happy Holiday. Stay healthy and safe. The encrypted file might look something like the following depending on what keys are used. (There are some nonprintable characters.) Saved it as encrypt.txt. 5*\$b\$,%b.\$a6)’a1\$/\$15’3b(1a,\$#3lLHsrsra* 1a \$’/b b7’3;a150 ,&’a;\$#3lLH+2*(,&b .-b.\$a;.7a#a 21;a ..(& ;oOK5#8b)’ .5*8b ,%b2#”- Then when you decrypt the file, encrypt.txt, it should return back to the end of the semester is near. 2020 has been a very strange year. Wishing all of you a Happy Holiday. Stay healthy and safe.

Order your essay today and save 10% with the discount code ESSAYHELP