Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Extra Credit # 5 ( extra 5 . c ) - - - XOR Encryption - - - Due: on last day of class by
Extra Credit #extrac XOR Encryption Due: on last day of class by :PM
Name your program: extrac
The main point of this extra credit assignment, is to get more practice with File input
output processesfunctions and to create your own little encryption program.
For this extra credit assignment, you need to create a program that reads in a textfile
specified by the user performs a bitlevel ExclusiveOR on each byte of the textfile
as a method of encryption then writes the encrypted file data back out to disk and
gives the encrypted file the same name as the input file ie so it overwrites the original
file
XOR encryption is a symmetric encryption algorithm, which means, the encrypted file
can also be decrypted with the same XOR algorithm as long as you use the same
encryption key, which you will, because the encryption key is hardcoded a variation
of this program would be to ask the user to enter the encryption key
So when testing your program keep a backup copy of the file to be encrypted then do
the following:
Create a text file make a backup copy and encrypt it
Use cat or vi to view the text file to see that its encrypted
Run the encryption again on the encrypted file, and then see if its decrypted
Below is the description of the UserApplication interaction:
You will need to refer to pages th edition or th edition of the
textbook for information on the bitlevel ExclusiveOR operator which you will need
for the encryption process.
You can also search the web for XOR encryption to see code examples and more
information.
DESCRIPTION
User types extra
Application Asks user to enter name of file to be encrypted.
User Enters name of file this file should be in the same directory as the executable file extra
Application Encrypts each byte of the input file and writes encrypted data back to the same file, over
writing the original data.
Some example code for an XOR encryption function
#include
#include
#include
int encryptdataFILE ;
int main void
FILE fileptr;
int returncode;
get file name from user, then do fopen for reading & writing
returncode encryptdata fileptr ;
fclosefileptr;
return ;
int encryptdataFILE diskfileptr
int i; Used to index through filebuffer
unsigned long int filesize; Holds number of bytes in the file
int keylength; Holds length of encryption key
char filebuffer NULL;
char keyABCDEF; default encryption key, you can change to
something else if you
want eg keyYghsss;
keylength strlenkey;
fseekdiskfileptr SEEKEND; Move filepointer to end of file.
filesize ftelldiskfileptr; Get current file pointer location
which will be the size of the file
in bytes
rewinddiskfileptr; Move filepointer back to beginning of file
Next step is to allocate RAM memory to hold all the bytes that are
currently stored on the HardDisk
filebuffer mallocfilesize;
Read file bytes into RAM filebuffer which is just an array of chars
if freadfilebuffer, filesize, diskfileptr
printfError in reading file
;
return ; returning error code
for i; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started