Hey everyone, I'm having some trouble finishing a code that is a Caesar Cipher with some modifications.
"Write a program to decrypt a message located in a file named “encrypted.txt” then print the decrypted message to the screen and a new file named “decrypted.txt” .“encrypted.txt” has been created for you using a Caesar Cipher. Two things are different though.First, to ease some of the requirements for this assignment, we will not worry about ensuring that all encrypted values will be a letter (a-z and A-Z).Lastly, the encryption process has been completed using a random shift value.You must ask the user to supply a seed, which is being used as a passcode, to decrypt the message correctly.In addition, the encryption process has attempted to prevent characters from being encrypted as non-printable characters.So, the random shift has been restricted to values between 0 and 4, inclusive."
What I have thus far is:
I thought this would of worked, but it seems to have problems on the upload site. I was wondering If anyone had any ideas on what I was doing wrong. Thanks for any and all help.
printf("Enter the passcode:\n ");
if((fp = fopen("encrypted.txt", "r")) == NULL)
printf("Error: Can't Open encrypted.txt\n");
if((fw = fopen("decrypted","a")) == NULL)
printf("Error: Can't Open decrypted.txt\n");
if( p >= 0 && p <= 4)
c = fgetc (fp);
c += rand() %p;
fprintf(fw, "%c", c);
} while ( c != EOF );