Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

clear text and writes the clear text to a file (make sure to use a different file name than the original file so you can

image text in transcribedimage text in transcribed

clear text and writes the clear text to a file (make sure to use a different file name than the original file so you can compare the results) Part 2: One Time Pad Encryption One Time Pad (OTP) encryption, when implemented properly, cannot be hacked by cryptanalysis. This method uses the clear text message to be encrypted), a random key of characters (the same size of the clear text) and the exclusive OR (XOR) operator. The table below contains the truth tables for bitwise XOR operators. This operator works bit-by-bit on C data. Modify the read. file and write file functions to also accept an integer argument representing a fixed number of bytes to be read or written. This is to specify the number of bytes to be read from the cipher file, which may contain the EOF character, or write to the cipher text file, which may contain null chars. This is necessary because the cipher may contain both EOF and 10 characters. This will be explained further below. Sample function calls to read file and write.file: XOR (-) ol 0 1 The table below shows the result of encrypting the clear text A with the random key * using the bit-by-bit XOR bitwise operator. Each bit position in A is XORed with its respective bit in * producing cipher text 1. read.fileco, clean file); // Read in a file with of unknown length, getting the length from the file read. clear file is a string containing the path to the clear text file. This function returns a char array created with memory allocation. read. fileten, clear file); // Where len > zero, reads len chars from a file. clear file is a string containing the path to the clear text file. This function returns a char array created with memory allocation. 3. write file(0, key, kex file); // Writes a string to file until the O char is reached. key is the string of random chars and key file is a string containing the path of the text file. 4. write filetlen, cipher, cipher file); // Where len > zero, writes len chars to a file. cipher is the cipher string of chars and cipher file is a string containing the path of the text file. charlint hex Clear text bin 01000001 XOR 00101010 01101011 Rand key * Cipher text k 42 107 2A 6B The menu in main) should look like: The clear text can be recovered from the cipher text by using the cipher key and the XOR operator as shown in the table below. Encrypt a file: 1 Decrypt a file: 2 Exit: 3 Enter a choice: bin char Cipher text k int 107 hex 6B 01101011 XOR Rand key Clear text 42 65 24 41 00101010 01000001 I suggest using a loop in main to show the menu, get a choice from the user and a switch statement to execute the chosen function. For the first two choices, the necessary file names should be read by main() and passed to encrypt() and decrypto. To generate the random key, the length of the key and a char array pointer are passed to make cand key. After make..tand.key) completes, the char array contains the randomly selected chars. When the user chooses to exit the program by entering 3. the loop should exit. A There is an article about OTP at: https://en.wikipedia.org/wiki/One-time_pad from Part 1 and the following This project will require the use of the read, file) and write file functions: The make and key accepts the length of the random key char array and a pointer to this array. This function uses the stand(time(NULL)) function to seed the rand function and the rand function to get random chars. The rand() function accepts no argument and returns an integer value between 0 and RAND_MAX (32,767 on most Intel-based computers). The return from rand must be scaled between 0 and 255 and explicitly castes as a char before being added to the char array. The EOF (integer value of - 1) must not be selected as one of the chars in the array so it can be read back from a file during the decrypt operation. If EOF is detected as a random char, subtract 1 from the value to make it-2. It may also be a good idea to replace any null (integer value 0). This may interfere with writing to file and should be replaced with 1. A sample function call to make and key is: make tand. keyflen, key); // Where len > zero, generates and returns a random key of len chars. 1. main function with a menu including 3 choices: encrypt file, decrypt file and exit program. 2. make sand.key(length of key, key) generates a fixed length string of random chars. 3. encrypt(clear file, key file, cipher file) generates a random key using make cand key0, perform the clear text XOR ket text. byte-by-byte, to produce the cipher text string and write both the random key and cipher text strings to file. 4. decrypt(key file, cipher file, clear file) uses the cipher text XOR random key to recover the original The encrypt() function accepts the clear text, random key and cipher text file names as arguments. It reads the clear text files, generates a random key: performs XOR on clear text and random key producing the cipher text, and writes the cipher text to file. Sample function call for encount) encrypt(clear.file, keyfile.cipher file); // Where the three arguments are strings containing filenames. The decrypt() function accepts the random key, cipher text and cipher text file names as arguments. It reads the random key and cipher text files. Read the random key first using read. file and either getc (in a loop) or fgets to read the cipher text file due to the possibility of a stray EOF in the cipher file. Sample function for decrypt(): decrypt(keyfile.cipher.file, message file); // Where the three arguments are strings containing filenames. clear text and writes the clear text to a file (make sure to use a different file name than the original file so you can compare the results) Part 2: One Time Pad Encryption One Time Pad (OTP) encryption, when implemented properly, cannot be hacked by cryptanalysis. This method uses the clear text message to be encrypted), a random key of characters (the same size of the clear text) and the exclusive OR (XOR) operator. The table below contains the truth tables for bitwise XOR operators. This operator works bit-by-bit on C data. Modify the read. file and write file functions to also accept an integer argument representing a fixed number of bytes to be read or written. This is to specify the number of bytes to be read from the cipher file, which may contain the EOF character, or write to the cipher text file, which may contain null chars. This is necessary because the cipher may contain both EOF and 10 characters. This will be explained further below. Sample function calls to read file and write.file: XOR (-) ol 0 1 The table below shows the result of encrypting the clear text A with the random key * using the bit-by-bit XOR bitwise operator. Each bit position in A is XORed with its respective bit in * producing cipher text 1. read.fileco, clean file); // Read in a file with of unknown length, getting the length from the file read. clear file is a string containing the path to the clear text file. This function returns a char array created with memory allocation. read. fileten, clear file); // Where len > zero, reads len chars from a file. clear file is a string containing the path to the clear text file. This function returns a char array created with memory allocation. 3. write file(0, key, kex file); // Writes a string to file until the O char is reached. key is the string of random chars and key file is a string containing the path of the text file. 4. write filetlen, cipher, cipher file); // Where len > zero, writes len chars to a file. cipher is the cipher string of chars and cipher file is a string containing the path of the text file. charlint hex Clear text bin 01000001 XOR 00101010 01101011 Rand key * Cipher text k 42 107 2A 6B The menu in main) should look like: The clear text can be recovered from the cipher text by using the cipher key and the XOR operator as shown in the table below. Encrypt a file: 1 Decrypt a file: 2 Exit: 3 Enter a choice: bin char Cipher text k int 107 hex 6B 01101011 XOR Rand key Clear text 42 65 24 41 00101010 01000001 I suggest using a loop in main to show the menu, get a choice from the user and a switch statement to execute the chosen function. For the first two choices, the necessary file names should be read by main() and passed to encrypt() and decrypto. To generate the random key, the length of the key and a char array pointer are passed to make cand key. After make..tand.key) completes, the char array contains the randomly selected chars. When the user chooses to exit the program by entering 3. the loop should exit. A There is an article about OTP at: https://en.wikipedia.org/wiki/One-time_pad from Part 1 and the following This project will require the use of the read, file) and write file functions: The make and key accepts the length of the random key char array and a pointer to this array. This function uses the stand(time(NULL)) function to seed the rand function and the rand function to get random chars. The rand() function accepts no argument and returns an integer value between 0 and RAND_MAX (32,767 on most Intel-based computers). The return from rand must be scaled between 0 and 255 and explicitly castes as a char before being added to the char array. The EOF (integer value of - 1) must not be selected as one of the chars in the array so it can be read back from a file during the decrypt operation. If EOF is detected as a random char, subtract 1 from the value to make it-2. It may also be a good idea to replace any null (integer value 0). This may interfere with writing to file and should be replaced with 1. A sample function call to make and key is: make tand. keyflen, key); // Where len > zero, generates and returns a random key of len chars. 1. main function with a menu including 3 choices: encrypt file, decrypt file and exit program. 2. make sand.key(length of key, key) generates a fixed length string of random chars. 3. encrypt(clear file, key file, cipher file) generates a random key using make cand key0, perform the clear text XOR ket text. byte-by-byte, to produce the cipher text string and write both the random key and cipher text strings to file. 4. decrypt(key file, cipher file, clear file) uses the cipher text XOR random key to recover the original The encrypt() function accepts the clear text, random key and cipher text file names as arguments. It reads the clear text files, generates a random key: performs XOR on clear text and random key producing the cipher text, and writes the cipher text to file. Sample function call for encount) encrypt(clear.file, keyfile.cipher file); // Where the three arguments are strings containing filenames. The decrypt() function accepts the random key, cipher text and cipher text file names as arguments. It reads the random key and cipher text files. Read the random key first using read. file and either getc (in a loop) or fgets to read the cipher text file due to the possibility of a stray EOF in the cipher file. Sample function for decrypt(): decrypt(keyfile.cipher.file, message file); // Where the three arguments are strings containing filenames

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

Recommended Textbook for

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

10. What is meant by a feed rate?

Answered: 1 week ago